changeset 25436:d24cf1a4dd34

(push, pop): New macros.
author Richard M. Stallman <rms@gnu.org>
date Sun, 29 Aug 1999 20:23:54 +0000
parents 5ff4e59e5f02
children 95301c74bdd9
files lisp/subr.el
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Sun Aug 29 19:54:39 1999 +0000
+++ b/lisp/subr.el	Sun Aug 29 20:23:54 1999 +0000
@@ -51,6 +51,21 @@
   ;; depend on backquote.el.
   (list 'function (cons 'lambda cdr)))
 
+(defmacro push (value listname)
+  "Add VALUE to the list which is the value of LISTNAME.
+This is equivalent to (setq LISTNAME (cons VALUE LISTNAME)).
+LISTNAME must be a symbol."
+  (list 'setq list
+	(list 'cons value list)))
+
+(defmacro pop (listname)
+  "Return the first element of LISTNAME's value, and remove it from the list.
+LISTNAME must be a symbol whose value is a list.
+If the value is nil, `pop' returns nil but does not actually
+change the list."
+  (list 'prog1 (list 'car listname)
+	(list 'setq listname (list 'cdr listname))))
+
 (defmacro when (cond &rest body)
   "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
   (list 'if cond (cons 'progn body)))