Created
August 12, 2014 03:06
-
-
Save y2q-actionman/f458ae5b3bea39075239 to your computer and use it in GitHub Desktop.
Haskell の $ もどき in Common Lisp
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
;; Haskell の $ もどき in Common Lisp | |
;; http://practical-scheme.net/wiliki/wiliki.cgi?Gauche%3A%24 | |
;; (fn1 $ fn2 $ fn3 $ fn4 x) -> (fn1 (fn2 (fn3 (fn4 x)))) | |
(defun $-expand (forms) | |
(cond ((null forms) | |
nil) | |
((eq '$ (car forms)) | |
(list ($-expand (cdr forms)))) | |
(t | |
(cons (car forms) ($-expand (cdr forms)))))) | |
(defmacro $ (&body forms) | |
($-expand forms)) | |
#| | |
CL-USER> (macroexpand-1 '($ fn1 $ fn2 $ fn3 $ fn4 x)) | |
(FN1 (FN2 (FN3 (FN4 X)))) | |
T | |
CL-USER> (macroexpand-1 '($ f a b c)) | |
(F A B C) | |
T | |
CL-USER> (macroexpand-1 '($ f $ g a b c)) | |
(F (G A B C)) | |
T | |
CL-USER> (macroexpand-1 '($ f $ g $ h a b c)) | |
(F (G (H A B C))) | |
T | |
CL-USER> (macroexpand-1 '($ f a $ g b $ h c)) | |
(F A (G B (H C))) | |
T | |
CL-USER> ($ 1+ $ 1+ 2) | |
4 | |
CL-USER> ($ 1+ $ 1+ ($ 1+ 2)) | |
5 | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment