This implements a version of the famous clojure threading macros.
(use-modules (syntax threading)) ;; ~> inserts arguments in the leftmost position (~> 5 (+ 4) (/ 3)) ;; => 3 ;; You can also use the placeholders <> and <...> (~> (list 1 2 3) (cons -1 <>) (+ <...>)) ;; => 5 ;; it also supports threading lambdas ((lambda~> (+ 4) (/ 3)) 5) ;; => 3 ;; and~> stops the execution if any expression returns #f (and~> 5 (- <> 1) (= 5) (display <>)) ;; => #f
~> left threading
~>> right threading
and~> left threading that stops when any intermediate value is #f
and~>> right threading version of and~>
lambda~> (lambda~> (-) abs) is the same as (lambda (id) (abs (- id)))
(define~> id ... is the same as (define id (lambda~> ...))
These are syntax-rules macros, and are as such portable across r(5 6 7)rs-conforming implementations. R6RS implementations might have some issuse using both srfi-26 and (syntax threading) at the same time due to module issues unless you import the <> and <...> bindings from srfi-26 and re-export them.
BSD-style with less restrictions. See the source files for the license text.