| (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