Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
streams and trees in elisp using loop
(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