pipe

Matthew Fulmer tapplek at gmail.com
Sat Aug 25 02:17:23 UTC 2007


On Fri, Aug 24, 2007 at 10:57:48PM +0200, Fabio Filasieno wrote:
> II'm new at Smalltalk and I have a few questions.
> """Why smalltalk has no operator for piping ?""""
> 
> obj collect: [ :x | ?] | filter: [:x | ?] | select: [:x | ?] ?

I don't understand what a pipe is or should do, other than save
a few parentheses. I am guessing you want the above to be
equivilant to 
 (( obj collect: [ :x | ?] ) filter: [:x | ?] ) select: [:x | ?]

(by the way, filter: is not a Smalltalk message)

One reason there is no pipe operator is that '|' is a valid
message and has many implementors in the image already.

More importantly, the above chain of messages is bordering on
the comprehensable and should probably be split up into more
statements or methods.

> but has the `;` (cascade operator)?
> 
> I don?t care to send messages to the reciever of the previous  
> message, because I return self when no return value is important; for  
> instance ?.
> 
> point x: 10 | y: 20 | z: 30
> 
> x returns self, y returns self, z returns self -> which is the  
> updated point.
> 
> works exactly as:
> 
> point x:10;  y:20 ;  z:30.
> 
> But you lose PIPES !!!!! Can somebody elaborate on this ?
> 
> There might be cases where I'm returning a value and I wish to  
> discard it and then send again to the previous receiver ... but I  
> really don't like to loose the pipe for that ... since I can do that  
> returning self.

You raise a fair point; most messages retrurn self anyway, and
they are the ones that ; is usually used with anyway, so it is a
bit redundant.

> With Smalltalk ... we've got a homoiconic language and the system  
> written in it self, a consistent language in everything, even the if- 
> then-else that everybody else still don't get right; we've got the  
> most wonderful programming experience of all, even better that Ruby/ 
> Python etc ...
> 
> but why on earth we have the "cascade operator" instead of the  
> PIPE ?????
> What I'm I missing ?
>
> I need the `|` to avoid parenthesis, and weird hacks ...

Like what?

What do you mean by pipes? Are you refering to some kind of
streaming like in bash where output can be generated from one
process and input to another with finite memory? If so, I am not
sure that is possible in general; objects are not always
serializable.

What kind of use case do you have in mind?

-- 
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808



More information about the Squeak-dev mailing list