Last active
October 27, 2015 15:32
-
-
Save lepoetemaudit/5ad6b67bd07dce0f6cc7 to your computer and use it in GitHub Desktop.
Macro for polish notation (prefix, i.e. not postfix RPN) in Clojure
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
(defmacro pln [& args] | |
(let [operator-count (dec (/ (count args) 2)) | |
operators (take operator-count args) | |
values (drop operator-count args) | |
op-vals (map vector operators (next values))] | |
(loop [form (first values) | |
op-vals op-vals] | |
(if (not-empty op-vals) | |
(let [[op val] (first op-vals)] | |
(recur | |
(list op form val) | |
(rest op-vals))) | |
form)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment