Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Using multiple reference to the same object

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44116] Using multiple reference to the same object
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Thu, 23 Oct 2003 07:15:14 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I've come across a rather puzzling situation involving multiple references
to objects I've created using the Class package from Dr. Maeder's _Computer
Science_ /with Mathematica/ book.  I created a 3D List of objects using
points=Table[new[myPoint, parent,i,j,k],{i, x0, x1}, {j, y0, y1}, {k, y0,
y1}] where points is a member of parent.

In the constructor for myPoint, I append the new instance to a List in
parent, called 'elements'. myPoint has a setColor method which I call like
this: setColor[points[[i]][[j]][[k],RGBColor[0,0,1]].  I also have a
getGraphics method in parent which does getGraphics&/@elements, where
getGraphics[myPoint] returns {color,Point[{x,y,z}]}.

Now, here's the rub: when I use the getGraphics method, I get back a list of
points all with the default color RGBColor[1,0,0].  If I explicitly do a
getGraphics[points[[i]][[j]][[k]], I get a blue (RGBColor[0,0,1]) point
back.  There are clearly two different point objects, one in the elements
List, and one in the points List.

What I want is the kind of behavior I get with C/C++ & Java arrays where I
can reference the same object from multiple references.  There may be a way
to do this using the Class package, but I'm interested in knowing if there
is a native Mathematica approach to doing the same thing.

Someone may have already given me an answere to this general question, and
it just didn't sink in.
-- 
"Philosophy is written in this grand book, The Universe. ... But the book
cannot be understood unless one first learns to comprehend the language...
in which it is written. It is written in the language of mathematics, ...;
without which wanders about in a dark labyrinth."   The Lion of Gaul


  • Prev by Date: [no subject]
  • Next by Date: Re: Advice on defining a data structure in Mathematica
  • Previous by thread: [no subject]
  • Next by thread: LogLogListPlot, LogLinearListPlot- Ticks and TickMarks