Created
September 7, 2017 08:23
-
-
Save alphapapa/f9e4dceaada6c90c613cd83bdc9a2300 to your computer and use it in GitHub Desktop.
Emacs Lisp: -$ macro
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
(defmacro -$ (&rest body) | |
(cl-labels ((collect-vars | |
(&rest forms) | |
(cl-loop for form in forms | |
append (cl-loop for atom in form | |
if (and (symbolp atom) | |
(string-match (rx bos "$") | |
(symbol-name atom))) | |
collect atom | |
else if (consp form) | |
append (collect-vars atom))))) | |
`(lambda ,(cl-sort (collect-vars body) | |
#'string< | |
:key #'symbol-name) | |
,@body))) | |
;; Used like: | |
;; (let ((l '((1 "one" :one) (2 "two" :two)))) | |
;; (cl-loop for triple in l | |
;; for (digit word symbol) = triple | |
;; collect (funcall (-$ (list (list $3 $2) $1)) | |
;; digit word symbol))) | |
;; => (((:one "one") 1) ((:two "two") 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment