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: Tue, 17 Nov 2009 16:34:53 -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 1258494168 6917 80.91.229.12 (17 Nov 2009 21:42:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2009 21:42:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 17 22:42:41 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 1NAVov-0004xB-FK for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Nov 2009 22:42:41 +0100 Original-Received: from localhost ([127.0.0.1]:37981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAVov-0002K3-00 for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Nov 2009 16:42:41 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!goblin1!goblin2!goblin.stu.neva.ru!feeder.erje.net!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 33 Original-X-Trace: barmar.motzarella.org 1258493692 17546 24.34.107.14 (17 Nov 2009 21:34:52 GMT) Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Tue, 17 Nov 2009 21:34:52 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Original-Xref: news.stanford.edu gnu.emacs.help:174781 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:69854 Archived-At: In article <9af6462e-4a2e-4325-b11d-9d8a6c2686b5@r24g2000yqd.googlegroups.com>, LanX 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, 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 ***