From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joe Corneli Newsgroups: gmane.emacs.help Subject: Re: sharing list structure Date: Thu, 24 Mar 2005 18:27:28 -0600 Message-ID: References: <6dbd4d00050324161731ef0f51@mail.gmail.com> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1111710531 10011 80.91.229.2 (25 Mar 2005 00:28:51 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Mar 2005 00:28:51 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 25 01:28:50 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DEcgy-0000Ww-4u for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 01:28:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEcwL-000610-PP for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Mar 2005 19:44:41 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DEcvw-0005yv-9d for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:44:16 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DEcvp-0005vZ-Nv for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:44:09 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEcvp-0005u2-1j for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:44:09 -0500 Original-Received: from [146.6.139.124] (helo=dell3.ma.utexas.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DEcfn-0000m2-Ka for help-gnu-emacs@gnu.org; Thu, 24 Mar 2005 19:27:35 -0500 Original-Received: from lab45.ma.utexas.edu (mail@lab45.ma.utexas.edu [128.83.133.159]) by dell3.ma.utexas.edu (8.11.0.Beta3/8.10.2) with ESMTP id j2P0RSC14498; Thu, 24 Mar 2005 18:27:28 -0600 Original-Received: from jcorneli by lab45.ma.utexas.edu with local (Exim 3.36 #1 (Debian)) id 1DEcfg-0002gI-00; Thu, 24 Mar 2005 18:27:28 -0600 Original-To: help-gnu-emacs@gnu.org In-reply-to: <6dbd4d00050324161731ef0f51@mail.gmail.com> (message from Denis Bueno on Thu, 24 Mar 2005 19:17:15 -0500) 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:25127 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25127 > > 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. Note the `setq' above, which make it look an awful lot like the structure of A *is* being modified. I mean, it comes out as a different list -- (progn (setq A '(1 2 3)) (setq B (list 'foo)) (setcdr B A) (setq A (append A (list 4))) A) ;=> (1 2 3 4) > 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. OK, I think I've got the idea now. But still, I'm surprised that `setq' is not among the list of "destructive functions". What's that about?