Created
February 10, 2019 16:46
-
-
Save nkanaev/73b7393252a04e8b908b2e724ba567d7 to your computer and use it in GitHub Desktop.
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 rpn (&rest tokens) | |
(let ((st (list))) | |
(dolist (x tokens (pop st)) | |
(if (symbolp x) | |
(let* ((op2 (pop st)) | |
(op1 (pop st))) | |
(push (list x op1 op2) st)) | |
(push x st))))) | |
(assert (equal 3 (rpn 1 2 +))) | |
(assert (equal 2 (rpn 1 2 *))) | |
(assert (equal 1 (rpn 1 2 - 5 * 6 +))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment