[Top][All Lists]

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

Re: sharing list structure

From: Joe Corneli
Subject: Re: sharing list structure
Date: Thu, 24 Mar 2005 19:42:31 -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.
   There will certainly be some kid gloves involved because most of
   the normal things you might want to do with A are destructive or
   subversive to any pointer B might hold.  The reason is, B is a
   symbol in an obarray that points to a list element.  That list
   element might have a CDR which points to the same list element
   that A points to but a change to A list can never cause the
   pointer held by some element in list B to change. So any
   operation involving setq A will very likely cause the
   corresponding pointer in list B to point to an obsolete location.

Well, I might be able to get by with using destructive functions to
modify list A.  It might be worth giving it a shot as an
exercise...  and if it works, so much the better.

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

   I'm pretty sure this is not what you are looking for since
   the position of the contents of B within list A is fixed.

   (defmacro a+b () '`(,@A ,@B))  ;or any number of similar things
   (setq A '(a b c d))
   (setq B '(1 2 3 4))
     => (a b c d 1 2 3 4)
   (setq a '(w x y z))
   (setq b '(9 8 7 6))
     => (w x y z 9 8 7 6)

I think that you're right that this isn't quite like what I'm after.

Let me describe the situation a bit better more... hopefully the
details won't be overwhelming.

I have two lists, H and F, and they both grow, shrink, and otherwise
change.  But, actually, I have several pairs of lists like this, H1,
F1, H2, F2, etc., and at any given point in time, exactly one matched
pair is to be assigned to H and F,

  H := Hk
  F := Fk

However, I'm not just handed the H1 F1, ..., Hn Fn, rather, I wish to
build up the collection from H's and F's over time.  Thus, sometimes I
also wish to run

  Hj := H
  Fj := F

The data structure that I think ought to be capable of handling all of
this would be a list B that contains

 ((title1, H1, F1), (title2, H2, F2), ..., (titlen, Hn, Fn))

This imposes an order on the of pairs Hk, Fk, and can be used at any
give point in time to select the kth pair, or to do the assignment
above, or just to manage all of this data.  Of course, the list B
can't have a fixed length in this set-up, since new Hk, Fk pairs may
appear, or old ones deleted.

   To be honest, I can't think of a way to do what it seems you
   want in *any* language.

Hopefully now that I've described the situation a bit more precisely
it will be clear that it could be done with pointers:

  -> (V  V  V)
      T1 H1 F1
  -> (V  V  V)
      T2 H2 F2

The vertical dimension here is dynamic, and there is a 3rd dimension
that is also dynamic, and it would be a pain to code it, I think, but
it seems manageable.  You'll have to forgive the quaint drawing style;
I fear it mainly will illustrate my lack of C programming sense.

reply via email to

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