Incongruent hash

David N. Smith dnsmith at watson.ibm.com
Thu Feb 12 16:08:01 UTC 1998


At 9:00 -0500 2/12/98, Tim Olson wrote:
>>I don't like the proposed arrow notation, since it reads naturally as "goes
>>to" or "becomes" or "maps into", none of which are any more true than @
>
>Plus, the -> notation is already used to create Associations (which fall
>into the "maps into" category, above).
>

Well, gee, I started off saying *I* didn't like it, and I sure didn't
'propose' it. I'd forgotton about associations in squeak using that
notation.

There is a problem with all notations using binary operators in that a 3D
vector is expensive to create. One first sends -> (or whatever) to a number
to get a 2D vector, then sends -> to the 2D vector to get a 3D vector,
meanwhile throwing away the 2D vector.

I've always wanted a general constructor, like {2.3.4} but which produces
things other than arrays. Maybe someone has done one and I haven't seen it
(or, as my age progresses, it's lost in the fog).


***NOT A PROPOSAL***

A 'simple' notation occurs to me, and it is not a proposal but a discussion
item, where a class name is followed by expressions in curly brackets:

   Array{a. b. c}        is equivalent to {a. b. c}
   Set{a. b. c}          is equivalent to (Set with: a with: b with: c)

Then, either of:

   Vector{x. y. z}       which is equivalent to (Vector   x: x y: y z: z)
   Vector3D{x. y. z}     which is equivalent to (Vector3D x: x y: y z: z)

could produce a vector with 3 coordinates. (I'm assuming there is an
abstract parent class named Vector, of course.)

There are three problems with this that I see offhand:

* It requires a compiler change.

* It doesn't well support classes that aren't collection-like.

* While the code is shorter than an equivalent class message, one does have
to write more than with binary messages.

Then there is the question of the protocol the compiler uses to create such
objects. It would have to ask the class for the name of a class method
which can be sent with n items:

   Vector selectorForInstanceCreation: numberOfItems

which might return #x:y:z:. Then the compiler does a perform to create the
object.

But if the class is a collection, and there are more items than there are
with: methods, what happens? Alan Wirfs-Brock and somebody else (J.
Eweing?) proposed (OOPSLA '96 Smalltalk Extensions workshop) a mechanism
where a one method can act as if it had a large number of, say, with:
keywords, but I don't think it's ever been implemented. It allowed things
like:

   obj employeeName: n address: a1 address: a2 address: a3 city: c

to be implemented with a method with the header:

   employeeName:address:*city:

where the asterisk means to repeat as needed. So, a collection might have a
method 'named:

   #with:*

and the parameter that is passed, as I recall, is a collection of the
parameters to all the individual with: keywords. (The proposal let the
existing #wiht:,#with:with: and #with:with:with: methods stay since they
are commonly used and faster than the general mechanism).

Short of something like Alan's proposal, I suppose the compiler could
special case collections, but I like general solutions.

***END OF NOT A PROPOSAL***   :-)

Dave


_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list