[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
- Remove last element in a list, Nordlöw, 2009/11/17
- Re: Remove last element in a list, LanX, 2009/11/17
- Reverse pop, return value, LanX, 2009/11/17
- Re: Reverse pop, return value, Lennart Borgman, 2009/11/17
- Message not available
- Re: Reverse pop, return value, LanX, 2009/11/17
- Re: Reverse pop, return value, Barry Margolin, 2009/11/17
- Re: Reverse pop, return value,
LanX <=
- Re: Reverse pop, return value, Barry Margolin, 2009/11/19
- Re: Reverse pop, return value, David Kastrup, 2009/11/17
- Re: Reverse pop, return value, LanX, 2009/11/17
Re: Remove last element in a list, Barry Margolin, 2009/11/17