Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created September 29, 2015 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosh04/fa409346388c324686f4 to your computer and use it in GitHub Desktop.
Save kosh04/fa409346388c324686f4 to your computer and use it in GitHub Desktop.
Clojure like fn macro #(...) on newLISP
(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