help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reverse pop, return value


From: LanX
Subject: Re: Reverse pop, return value
Date: Tue, 17 Nov 2009 16:28:35 -0800 (PST)
User-agent: G2/1.0

Hi

On 17 Nov., 22:34, Barry Margolin <bar...@alum.mit.edu> wrote:
> As I mentioned in the "remove last element in a list" thread, this won't
> work when the list gets down to 1 element.  nbutlast works by changing
> the cdr of the 2nd-to-last cons cell in the list to point to nil.  But
> if there's only 1 element, there's no 2nd-to-last cons cell to modify.  

Thx, so this is the way to go?

(defmacro rpop (LIST)
         "reverse pop"
         `(prog1
            (car (last ,LIST))
           (setq ,LIST (butlast ,LIST 1))
           )
         )

> You need to assign to the original variable, and this can only be done
> using a macro (that's why push and pop are macros).

Hmm, for better understanding, could it be done with a defun if I pass
a quoted symbol?

something like:

(rpop-symb 'list)

Cheers
  Rolf


reply via email to

[Prev in Thread] Current Thread [Next in Thread]