[Top][All Lists]

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

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

From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Works in Squeak but not GNU (deepCopy?)
Date: Fri, 18 Nov 2011 16:49:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1

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

        unitsImp := unitsImp collect: [ :each | each copy ]

        unitsImp := unitsImp copy

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.


reply via email to

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