From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Denis Bueno Newsgroups: gmane.emacs.help Subject: Re: sharing list structure Date: Thu, 24 Mar 2005 19:17:15 -0500 Message-ID: <6dbd4d00050324161731ef0f51@mail.gmail.com> References: Reply-To: Denis Bueno NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1111710239 9385 80.91.229.2 (25 Mar 2005 00:23:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Mar 2005 00:23:59 +0000 (UTC) Cc: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 25 01:23:59 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DEccB-000052-6Q for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 01:23:51 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEcrY-0004iO-NI for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Mar 2005 19:39:44 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DEcr9-0004h4-2T for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:39:19 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DEcr4-0004el-10 for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:39:14 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEcr3-0004df-Og for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:39:13 -0500 Original-Received: from [64.233.184.206] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DEcVo-0000Fw-Oi for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:17:16 -0500 Original-Received: by wproxy.gmail.com with SMTP id 36so777870wra for ; Thu, 24 Mar 2005 16:17:15 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=eIYVZkWLUa5RHxFnw5l4nSRlvwoOYKZfOjrbt7ZiUDbVQSZzZfyStpPq1Acu9k1WTsKDxroq0Fpn65smt6D/Poun59zAPm3FbEm0haxW1avfv81hQbVxhJevvQDkKIdRbyFUdbF6g/S0t1Ag/WH1kBJDJTR+4yHEjP4535kUCP8= Original-Received: by 10.54.21.62 with SMTP id 62mr115831wru; Thu, 24 Mar 2005 16:17:15 -0800 (PST) Original-Received: by 10.54.43.7 with HTTP; Thu, 24 Mar 2005 16:17:15 -0800 (PST) Original-To: Joe Corneli In-Reply-To: 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 X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: news.gmane.org gmane.emacs.help:25126 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25126 On Thu, 24 Mar 2005 17:48:57 -0600, Joe Corneli wrote: > > I'm not sure how to do the following: *snip* > > So I guess what I want is an "implicit pointer" to A. > > Looking at the box diagrams in the manual, it seemed to me that > everything would be taken care of if I used "setcdr" to build the list > B. But that didn't quite work: > > (progn > (setq A '(1 2 3)) > (setq B (list 'foo)) > (setcdr B A) > (setq A (append A (list 4))) > B) > ;=> (foo 1 2 3) The `append' doesn't alter the structure of the list A. (defvar *foo* (list 1 2 3)) (append *foo* (list 4 5 6)) *foo* => (1 2 3) Hence, the result of append doesn't alter A's structure. > If I handle A with kid gloves, then B comes out right: > > (progn > (setq A '(1 2 3)) > (setq B (list 'foo)) > (setcdr B A) > (setcdr (nthcdr 2 A) (list 4)) > B) > ;=>(foo 1 2 3 4) (setcdr (nthcdr ...) ...) _does_ alter A's structure. And thus it works. > But is this the only way to go? If it was possible, I would like to > set things up so that I could do anything I wanted to do to A, and > have B simply reflect that value at the end. You can do "anything you want" with A, as long as any function you run on A destructively modifies A. If it doesn't, then there's no way for B to reflect the change. So, just restrict yourself to destructive operations on A - like setcdr, setcar, etc. - and you'll be set. Just note that A will always have to be the "tail" part of B. I.e. something like B: (1 2 3 4 5 6) A: (3 4) ; a sublist of B won't work, just because of the nature of lisp lists. -- Denis Bueno PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index