Skip to content

Instantly share code, notes, and snippets.

@y2q-actionman
Created August 12, 2014 03:06
Show Gist options
  • Save y2q-actionman/f458ae5b3bea39075239 to your computer and use it in GitHub Desktop.
Save y2q-actionman/f458ae5b3bea39075239 to your computer and use it in GitHub Desktop.
Haskell の $ もどき in Common Lisp
;; 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