help-smalltalk
[Top][All Lists]
Advanced

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

Re: [Help-smalltalk] Works in Squeak but not GNU (deepCopy?)


From: Jimmy Johnson
Subject: Re: [Help-smalltalk] Works in Squeak but not GNU (deepCopy?)
Date: Fri, 18 Nov 2011 09:42:28 -0800 (PST)

Is there a way to look at / edit the code of deepCopy in Object?



________________________________
 From: Paolo Bonzini <address@hidden>
To: address@hidden 
Sent: Friday, November 18, 2011 10:49 AM
Subject: Re: [Help-smalltalk] Works in Squeak but not GNU (deepCopy?)
 
On 11/18/2011 01:42 PM, Jimmy Johnson wrote:
> I don't know where else to turn for help so...if one of you experts
> would have the time to look at this project and see if an obvious
> problem jumps out, and let me know, I would really appreciate it.
> 
> The project is to write a rational number class and include
> units/dimensions (meters/length).  The system works fine in Squeak
> SmallTalk, but fails in gnu SmallTalk.  I'm guessing it has something
> to do with my use of deepClone.

Yes, that's correct.  deepCopy is not standardized, but it traditionally made 
only a 1-level deep copy.

The better way to do it in GNU Smalltalk is to use "copy" and add postCopy 
methods such as

Unitable>>postCopy
    unitsImp := unitsImp collect: [ :each | each copy ]

DimensionedRational>>postCopy
    unitsImp := unitsImp copy
    
etc.

From a quick read of the code I'm not sure where you actually need deeper 
copies, so the above is likely incomplete or incorrect.

As an aside, I suggest that you replace all uses of "self length" with simply 
"1" (why is length special?) and merge the Constants and Dimensionable classes. 
 Also, the Comparable class is exactly the same as Magnitude, except that it 
doesn't test the precondition that the classes are the same.  In general such 
preconditions hamper the usage of polymorphism, so they're not used in 
Smalltalk.

Paolo

_______________________________________________
help-smalltalk mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-smalltalk


reply via email to

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