Last active
February 15, 2018 03:29
-
-
Save nulldatamap/f4edec50578824b4158f6ec6ace2bc37 to your computer and use it in GitHub Desktop.
Threading macros for 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
(define-syntax -> | |
(syntax-rules () | |
((_ val) | |
val) | |
((_ val (f args ...) rest ...) | |
(-> (f val args ...) | |
rest ...)) | |
((_ val f rest ...) | |
(-> (f val) | |
rest ...)))) | |
(define-syntax ->> | |
(syntax-rules () | |
((_ val) | |
val) | |
((_ val (f args ...) rest ...) | |
(->> (f args ... val) | |
rest ...)) | |
((_ val f rest ...) | |
(->> (f val) | |
rest ...)))) | |
(define-syntax as-> | |
(syntax-rules () | |
((_ val name) | |
val) | |
((_ val name (f args ...) rest ...) | |
(let ((name val)) | |
(as-> (f args ...) name | |
rest ...))) | |
((_ val name f rest ...) | |
(as-> val name (f) | |
rest ...)))) | |
(define-syntax if-> | |
(syntax-rules () | |
((_ val (then args ...) else) | |
(let ((x val)) | |
(if x | |
(then x args ...) | |
else))))) | |
(define-syntax if->> | |
(syntax-rules () | |
((_ val (then args ...) else) | |
(let ((x val)) | |
(if x | |
(then args ... x) | |
else))))) | |
(define-syntax if->* | |
(syntax-rules () | |
((_ (then args ...) else val) | |
(let ((x val)) | |
(if x | |
(then x args ...) | |
else))))) | |
(define-syntax if->>* | |
(syntax-rules () | |
((_ (then args ...) else val) | |
(let ((x val)) | |
(if x | |
(then args ... x) | |
else))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment