Created
December 9, 2012 17:10
-
-
Save nicferrier/4246140 to your computer and use it in GitHub Desktop.
streams and trees in elisp using loop
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
(let (stack | |
result | |
(stream '((START "a") | |
(START "b") | |
(START "c") | |
(TEXT "test 1") | |
(END "c") | |
(END "b") | |
(END "a")))) | |
(loop for (operator operand) in stream | |
do (case operator | |
('START | |
(let ((element (list operand))) | |
(if stack | |
(progn | |
(setcdr (elt stack 0) (list element)) | |
(push element stack)) | |
(setq stack (list element)) | |
(setq result stack)))) | |
('TEXT | |
(setcdr (elt stack 0) (list operand))) | |
('END | |
(pop stack)))) result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment