Storing and Retrieving Point
John M McIntosh
johnmci at smalltalkconsulting.com
Thu Sep 27 21:35:13 UTC 2001
>I'm having trouble storing and retrieving Points. What am I doing wrong?
>
>pt _ Point new.
>pt _ 25 at 125.
>dict _ Dictionary new.
>dict at: 'first' put: #('text' pt).
>readPt _ ((dict at: 'first') at: 2). "readPt is now a Symbol"
>
>Thx for any pointers.
>Ken
Mmm I think some others missed just a little wee issue. I noticed
that you assign pt the value Point new, then assign it 25 at 125.
Sometimes I've seen this from folks that are use to declaring the
type of a variable. In Smalltalk the variable is just a reference to
an object, it has no typing information.
Therefore all you really need to do is
pt _ 25 at 125
The compiler then converts the textual representation of the point
into an instance of point that is referred to by pt
Another thing that sometimes confuses people at first is doing
pt _ 25 at 125.
pt _ 15.66.
pt _ 'Hello'.
Somehow they feel that because pt was assigned an instance of Point
then how the heck do you reassign it another type? (without casting
eh?).
In any case I'll leave the issue of polymorhic features for another discussion.
--
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
===========================================================================
More information about the Squeak-dev
mailing list
|