Created
May 2, 2012 03:43
-
-
Save tizoc/2573417 to your computer and use it in GitHub Desktop.
clojure's -> and ->> for chibi scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (scheme) (clojure pipeline) (chibi test)) | |
(test | |
"(-> 3.0 (- 2) (* 5) sqrt)" | |
(sqrt (* (- 3.0 2) 5)) | |
(-> 3.0 (- 2) (* 5) sqrt)) | |
(test | |
"(->> 3.0 (- 5) (* 5) sqrt)" | |
(sqrt (* 5 (- 5 3.0))) | |
(->> 3.0 (- 5) (* 5) sqrt)) | |
(test | |
"(doto (make-vector 3) (vector-set! 0 0) (vector-set! 1 1) (vector-set! 2 2))" | |
(vector 0 1 2) | |
(doto (make-vector 3) (vector-set! 0 0) (vector-set! 1 1) (vector-set! 2 2))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-library (clojure pipeline) | |
(export -> ->> doto) | |
(import (scheme)) | |
(begin | |
(define-syntax -> | |
(syntax-rules () | |
((_ ?form) ?form) | |
((_ ?form (?f ?arg ...)) (?f ?form ?arg ...)) | |
((_ ?form ?f) (?f ?form)) | |
((_ ?form ?form2 . ?forms) (-> (-> ?form ?form2) . ?forms)))) | |
(define-syntax ->> | |
(syntax-rules () | |
((_ ?form) ?form) | |
((_ ?form (?f ?arg ...)) (?f ?arg ... ?form)) | |
((_ ?form ?f) (?f ?form)) | |
((_ ?form ?form2 . ?forms) (->> (->> ?form ?form2) . ?forms)))) | |
(define-syntax doto | |
(syntax-rules () | |
((_ ?form) ?form) | |
((_ ?form (?f ?arg ...)) (?f ?form ?arg ...)) | |
((_ ?form ?f) (?f ?form)) | |
((_ ?form ?form2 . ?forms) | |
(let ((value ?form)) | |
(doto value ?form2) | |
(doto value . ?forms) | |
value)))) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment