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

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

Reverse pop, return value


From: LanX
Subject: Reverse pop, return value
Date: Tue, 17 Nov 2009 07:32:53 -0800 (PST)
User-agent: G2/1.0

Hi

I tried to realize a reverse pop which pops from the end of the list,
but the code get's "lengthy"....

I need to define a local variable to hold the return value... is there
a more elegant way to do it?

 ----------- M-x ielm
ELISP> (defun rpop (LIST)
         "reverse pop"
         (let
            ( (ret (car (last LIST))) )
            (nbutlast LIST 1)
            ret
         )
       )
rpop
ELISP> (setq list '(a b c d e f g h i j))
(a b c d e f g h i j)

ELISP> (rpop list)
j
ELISP> (rpop list)
i
ELISP> (rpop list)
h
 -------------

There must be a technique to simplify this !?!
Thanx
  Rolf


reply via email to

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