all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Denis Bueno <dbueno@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: sharing list structure
Date: Thu, 24 Mar 2005 19:17:15 -0500	[thread overview]
Message-ID: <6dbd4d00050324161731ef0f51@mail.gmail.com> (raw)
In-Reply-To: <E1DEc4P-0002bS-00@lab45.ma.utexas.edu>

On Thu, 24 Mar 2005 17:48:57 -0600, Joe Corneli
<jcorneli@math.utexas.edu> 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

  reply	other threads:[~2005-03-25  0:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-24 23:48 sharing list structure Joe Corneli
2005-03-25  0:17 ` Denis Bueno [this message]
2005-03-25  0:27   ` Joe Corneli
2005-03-25  0:35     ` Denis Bueno
     [not found]   ` <mailman.176.1111711460.28103.help-gnu-emacs@gnu.org>
2005-03-25  1:21     ` Thien-Thi Nguyen
2005-03-26 23:58     ` Stefan Monnier
     [not found] <mailman.173.1111709565.28103.help-gnu-emacs@gnu.org>
2005-03-25  1:01 ` rgb
2005-03-25  1:42   ` Joe Corneli
     [not found]   ` <mailman.182.1111716692.28103.help-gnu-emacs@gnu.org>
2005-03-25  5:44     ` rgb
2005-03-25  5:49       ` rgb
2005-03-25  6:08       ` Joe Corneli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6dbd4d00050324161731ef0f51@mail.gmail.com \
    --to=dbueno@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.