Commits

Moritz Heidkamp  committed 12347a8 Merge

Merged in janherich/clojurian (pull request #2)

Add 'as->' macro to syntax

  • Participants
  • Parent commits f02b054, 83aed32

Comments (0)

Files changed (2)

File clojurian-syntax.scm

 (module clojurian-syntax
 
-(doto -> ->* ->> ->>* if-let if-let*)
+(doto as-> -> ->* ->> ->>* if-let if-let*)
 
 (import chicken scheme)
 
        ...
        val))))
 
+(define-syntax as->
+  (syntax-rules ()
+    ((_ state name) state)
+    ((_ state name expr)
+     (let ((name state))
+       expr))
+    ((_ state name expr rest ...)
+     (as-> (let ((name state))
+             expr) name rest ...))))
+
 (define-syntax ->
   (syntax-rules ()
     ((_ x) x)

File tests/syntax.scm

              (list 3)
              (append '(4))))
 
+  (test 3 (as-> 3 x))
+  (test 2 (as-> 1 x (+ x 3) (/ x 2)))
+  (test 5 (-> 10 (* 2) (as-> state (/ state 4))))
+
   (test 7 (-> 10 (- 3)))
   (test -7 (->> 10 (- 3)))