I want to use list as stack, to add and remove items from list.
(define-syntax push!
(syntax-rules ()
((_ var obj)
(set! var (cons obj var)))))
(define-syntax pop!
(syntax-rules ()
((_ var)
(let ((top (car var)))
(set! var (cdr var))
top))))
Credit: Jakub T. Jankiewicz
based on code by Nils M Holm (ref: setters.scm)
(let ((x ()))
(push! x 'foo)
(push! x 'bar)
(push! x 'baz)
(display x)
(newline)
(display (pop! x))
(newline)
(display x)
(newline))
;; ==> (baz bar foo)
;; ==> baz
;; ==> (bar foo)