help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sharing list structure


From: Joe Corneli
Subject: sharing list structure
Date: Thu, 24 Mar 2005 17:48:57 -0600

I'm not sure how to do the following:

 I have a list A, that grows, shrinks, and changes.

 I want to have a list B that includes list A within
 its list structure, along with other things, and that
 automatically keeps the "A" part of itself in synch
 with A.

If this was C, I think what I guess what I would say I want is a
"pointer to A".

But the elisp manual says --

   A note to C programmers: in Lisp, we do not distinguish between
   "holding" a value and "pointing to" the value, because pointers in
    Lisp are implicit.

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)

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)

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.

Is there a way to accomplish this?  And if it can't be done with
list structure alone, what other suggestions can you make?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]