Created
August 11, 2014 10:49
-
-
Save y2q-actionman/85d68c759a15e7134640 to your computer and use it in GitHub Desktop.
簡易 method chain 的なやつ 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
(defun suffix-transpose1 (form terminal) | |
(if form | |
(suffix-transpose1 (cdr form) | |
(list (cons (car form) terminal))) | |
terminal)) | |
(defun suffix-transpose (form) | |
(car (suffix-transpose1 (cdr form) | |
(list (car form))))) | |
;; (5 1+ 1+ 1+) -> (1+ (1+ (1+ 5))) | |
(defmacro => (&body forms) | |
(suffix-transpose forms)) | |
;; (=> 1 1+ 1+ 1+) -> 4 | |
#| | |
CL-USER> (=> 1 1+ (lambda (x) (progn (pprint x) x)) 1+) | |
2 | |
3 | |
CL-USER> | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment