comparison lisp/subr.el @ 25436:d24cf1a4dd34

(push, pop): New macros.
author Richard M. Stallman <rms@gnu.org>
date Sun, 29 Aug 1999 20:23:54 +0000
parents 737e82c21934
children 95301c74bdd9
comparison
equal deleted inserted replaced
25435:5ff4e59e5f02 25436:d24cf1a4dd34
48 It may also be omitted. 48 It may also be omitted.
49 BODY should be a list of lisp expressions." 49 BODY should be a list of lisp expressions."
50 ;; Note that this definition should not use backquotes; subr.el should not 50 ;; Note that this definition should not use backquotes; subr.el should not
51 ;; depend on backquote.el. 51 ;; depend on backquote.el.
52 (list 'function (cons 'lambda cdr))) 52 (list 'function (cons 'lambda cdr)))
53
54 (defmacro push (value listname)
55 "Add VALUE to the list which is the value of LISTNAME.
56 This is equivalent to (setq LISTNAME (cons VALUE LISTNAME)).
57 LISTNAME must be a symbol."
58 (list 'setq list
59 (list 'cons value list)))
60
61 (defmacro pop (listname)
62 "Return the first element of LISTNAME's value, and remove it from the list.
63 LISTNAME must be a symbol whose value is a list.
64 If the value is nil, `pop' returns nil but does not actually
65 change the list."
66 (list 'prog1 (list 'car listname)
67 (list 'setq listname (list 'cdr listname))))
53 68
54 (defmacro when (cond &rest body) 69 (defmacro when (cond &rest body)
55 "(when COND BODY...): if COND yields non-nil, do BODY, else return nil." 70 "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
56 (list 'if cond (cons 'progn body))) 71 (list 'if cond (cons 'progn body)))
57 (put 'when 'lisp-indent-function 1) 72 (put 'when 'lisp-indent-function 1)