Path: utzoo!mnetor!uunet!mcvax!unido!laura!hmm From: hmm@laura.UUCP (Hans-Martin Mosner) Newsgroups: comp.lang.smalltalk Subject: Re: Question concerning behavior of assignment and copy methods Message-ID: <278@laura.UUCP> Date: 30 Mar 88 20:58:47 GMT References: <1868@rayssd.ray.com> <256@laura.UUCP> <3160@entire.UUCP> Reply-To: hmm@laura.UUCP (Hans-Martin Mosner) Organization: University of Dortmund, W-Germany Lines: 48 In article <3160@entire.UUCP> elt@entire.UUCP (Edward L. Taychert) writes: >I am writing an intelligent chess board in STV to help in some analysis; I set >the initial position of the board with a literal array. I was surprized >the second time I ran the program and, after initialization, got the >old board. This is normal. *Literals* are not the same as *constants*. They can be modified like any other kind of object. > Without understanding, I threw in a deep copy and it worked >fine. The documentation on deep copy is recursive "answer a deep >copy of the receiver". Basically, it's up to each class how it defines deepCopy. Characters, for instance, don't produce a real copy but just return themselves. The Object>>deepCopy method just creates a new object of the same class and size as the receiver, and fills its instance variables with deepCopies of its own instance variables. The shallowCopy method on the contrary just creates the new object and puts its own instance variables in it. Naturally, deepCopy only works for non-circular structures. >I've used lost of pointers and indirection in C; >if someone would help me and tell me what's going on, I will understand! Basically, each variable in Smalltalk just contains a pointer to an object, not the object itself (with the notable exception of SmallInteger objects). So in the shallowCopy just the pointers are copied, and the old objects and its copy share the objects pointed to. >But I can't understand STV by its external behavior. Isn't this stuff documented somewhere ? (hint: go buy the blue book) Hans-Martin > >____________________________________________________________________________ > >Ed Taychert Phone: USA (716) 381-7870 >Entire Inc. UUCP: rochester!rocksanne!entire!elt >435 E. Commercial Street >East Rochester, N.Y. 14445 A Xerox Company >_____________________________________________________________________________ ^^^^^ Why use Smalltalk V ? There's a Xerox Company which sells Real Smalltalk-80 :-) -- Hans-Martin Mosner | Don't tell Borland about Smalltalk - | hmm@unido.{uucp,bitnet} | they might invent Turbo Smalltalk ! | ------------------------------------------------------------------------ Disclaimer: Turbo Smalltalk may already be a trademark of Borland...