clojurian / clojurian-syntax.scm

(module clojurian-syntax

(doto -> ->* ->> ->>* if-let if-let*)

(import chicken scheme)

;; originally contributed by Martin DeMello
;; rewritten in terms of syntax-rules by Moritz Heidkamp
(define-syntax doto
  (syntax-rules ()
    ((_ x) x)
    ((_ x (fn args ...) ...)
     (let ((val x))
       (fn val args ...)
       ...
       val))))

(define-syntax ->
  (syntax-rules ()
    ((_ x) x)
    ((_ x (y z ...) rest ...)
     (-> (y x z ...) rest ...))))

(define-syntax ->>
  (syntax-rules ()
    ((_ x) x)
    ((_ x (y ...) rest ...)
     (->> (y ... x) rest ...))))

(define-syntax ->*
  (syntax-rules ()
    ((_ x) x)
    ((_ x (y z ...) rest ...)
     (->* (receive args x
            (apply y (append args (list z ...))))
          rest ...))))

(define-syntax ->>*
  (syntax-rules ()
    ((_ x) x)
    ((_ x (y z ...) rest ...)
     (->>* (receive args x
             (apply y (append (list z ...) args)))
           rest ...))))

(define-syntax if-let
  (syntax-rules ()
    ((_ (x y) then else)
     (let ((x y))
       (if x then else)))))

(define-syntax if-let*
  (syntax-rules ()
    ((_ ((x y) more ...) then else)
     (or (and-let* ((x y) more ...)
           then)
         else))))

)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.