In article , LanX wrote: > Hi > > On 17 Nov., 22:34, Barry Margolin 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)) > ) > ) Yes. > > > 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) Yes, that would work. That's why add-to-list requires a quoted symbol. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***