From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Reverse pop, return value Date: Thu, 19 Nov 2009 08:41:00 -0500 Organization: A noiseless patient Spider Message-ID: References: <9af6462e-4a2e-4325-b11d-9d8a6c2686b5@r24g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1258642267 7557 80.91.229.12 (19 Nov 2009 14:51:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Nov 2009 14:51:07 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 19 15:51:01 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NB8Ld-0006sb-1F for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 15:51:01 +0100 Original-Received: from localhost ([127.0.0.1]:49721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NB8Lc-0001VU-Mk for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 09:51:00 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!goblin1!goblin.stu.neva.ru!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-X-Trace: news.eternal-september.org U2FsdGVkX18fo3pl7EbasY9KYD0U/VxHM9ASMkbJD3ff2vxXUBnE9rfowdah07zC19+3OKjuQynXsbp4jOe9gCXTVfht8yIr9lS5DWoWnbQwT8n7YVOYHto5IFX1KlBD9V+uwffJvnE= Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Thu, 19 Nov 2009 13:41:01 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Auth-Sender: U2FsdGVkX18F/H1+LetQe0tcBkiyLK3Ljrzd90qqjNc= Cancel-Lock: sha1:d53T55VLHOEw4J+Wd6EDf8pNjfg= Original-Xref: news.stanford.edu gnu.emacs.help:174846 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69920 Archived-At: 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 ***