Protocol dilution?
Marcel Weiher
marcel at system.de
Wed Dec 16 13:35:11 UTC 1998
> I think we are actually talking different things. Your approach sounds
> very
> much like 'map' in functional programming, where a particular
function is
> applied
> (mapped) to all the elements in a collection. Is that right?
It does have connections with map in that it is a higher order
construct, but there are crucial differences.
> I was thinking more of passing an argument to a method. If the
argument is
> a single object, you would simply send it arg1 #fire, on the other
hand, if
> the argument is a collection arg1 #fire will fail. On the other
hand, if
> single
> objects understand do: then arg1 do: [each: each #fire] will work.
I dont
> see how collect solves this problem? does 5 collect 4 work in your
> example??
Yes, single arguments/receivers are wrapped so that they repeat in
the presence of collection arguments/receivers. So:
2 collect raisedTo: (1 to: 20)
repeats the receiver '2' while stepping through the argument
collection, sending the messages 2 raisedTo: 1, 2 raisedTo: 2, 2
raisedTo: 3 etc., whereas:
(1 to: 20) collect raisedTo:2
will repeat the argument while stepping through the receiver,
sending the messages 1 raisedTo: 2, 2 raisedTo: 2, 3 raisedTo: 2,
etc. Finally
(1 to:20) collect raisedTo:(1 to:20)
will step through both the argument and receiver. Hmm, maybe there
should be #cross, (1 to: 20) cross collect raisedTo:(1 to: 20)?
In your case, you one would probably use #do instead of #collect,
making the example read
arg1 do fire
which works for either collections or single objects.
> The other issue regarding tradeoffs is that writing the forwarding
> messages only
> needs to be done once, while "collect +" must be written on each
invocation.
> I think it may be cleaner syntactically to use '+', but as you
point out,
> there may then be ambiguity...
For messages that are sent to collections frequently, adding the
forwarders directly could be beneficial. However, the disadvantage
is that these special cases also have to be learned individually ( I
can send a,b,c to collections, but not x,y,z), whereas the syntax
just has to be learned once.
Btw, don't nail me down on specifics of the syntax, I am just
experimenting in this direction and especially the syntactic aspects
seem to have bewildering trade-offs.
Marcel
More information about the Squeak-dev
mailing list
|