[Top][All Lists]

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

Re: Reverse pop, return value

From: Barry Margolin
Subject: Re: Reverse pop, return value
Date: Tue, 17 Nov 2009 16:34:53 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article 
 LanX <address@hidden> wrote:

> Thanx Lennart!
> Thats what I was looking for! 8)
> ---------------
> (defun rpop (LIST)
>        "reverse pop"
>        (prog1
>             (car (last LIST))
>             (nbutlast LIST 1)
>        )
>        )
> --------------
> bye
>   rolf

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.  
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).

Barry Margolin, address@hidden
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 ***

reply via email to

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