From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: LanX Newsgroups: gmane.emacs.help Subject: Re: Reverse pop, return value Date: Tue, 17 Nov 2009 16:28:35 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <9af6462e-4a2e-4325-b11d-9d8a6c2686b5@r24g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1258504852 5228 80.91.229.12 (18 Nov 2009 00:40:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 18 Nov 2009 00:40:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 18 01:40:45 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 1NAYbF-0004qd-IL for geh-help-gnu-emacs@m.gmane.org; Wed, 18 Nov 2009 01:40:45 +0100 Original-Received: from localhost ([127.0.0.1]:43918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAYbF-0003jE-2G for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Nov 2009 19:40:45 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!c3g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 31 Original-NNTP-Posting-Host: 188.97.67.179 Original-X-Trace: posting.google.com 1258504115 24380 127.0.0.1 (18 Nov 2009 00:28:35 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 18 Nov 2009 00:28:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c3g2000yqd.googlegroups.com; posting-host=188.97.67.179; posting-account=W9fpQwoAAADZYmkl-8sXk1VPxG3rq-Pd User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.14) Gecko/2009090216 Ubuntu/8.10 (intrepid) Firefox/3.0.14, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:174787 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:69860 Archived-At: 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. =A0nbutlast works by changing > the cdr of the 2nd-to-last cons cell in the list to point to nil. =A0But > if there's only 1 element, there's no 2nd-to-last cons cell to modify. = =A0 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