Created
September 29, 2015 06:01
-
-
Save kosh04/fa409346388c324686f4 to your computer and use it in GitHub Desktop.
Clojure like fn macro #(...) on newLISP
This file contains 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-macro (\) | |
(expand | |
(append (fn ()) (list (args))) | |
'((% (args 0)) | |
(%1 (args 0)) | |
(%2 (args 1)) | |
(%3 (args 2)) | |
(%4 (args 3)) | |
(%5 (args 4))))) | |
(\ * % %) ;=> (lambda () (* (args 0) (args 0))) | |
((\ * % %) 10) ;=> 100 | |
((\ + %1 %2 %3) 1 2 3) ;=> 6 | |
(filter (\ even? %) (sequence 1 10)) ;=> (2 4 6 8 10) | |
(map (\ + 5 %) (sequence 1 10)) ;=> (6 7 8 9 10 11 12 13 14 15) | |
(map (curry + 5) (sequence 1 10)) ;=> (6 7 8 9 10 11 12 13 14 15) | |
(map (\ upper-case (trim %)) '("top " " test ")) ;=> ("TOP" "TEST") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment