Fabio's proposal:
make the ";" cascade operator send the message not the the previous receiver but to the object returned by the previous message send.
This would break most code with cascades, like:
o add: 1; add: 2; yourself.
Pipes might be useful in some cases, so one can add the following message to Object:
pipe: aBlock
| catcher pipedObject | catcher := MessageCatcher new privAccumulator: OrderedCollection new. aBlock value: catcher. pipedObject := self. catcher privAccumulator do: [ :each | pipedObject := each sendTo: pipedObject ]. ^pipedObject
Then simply use ; as a pipe like:
1 pipe: [ :mock | mock + 3; - 2; asFloat; * 2; asString; , ' foo'; , ' or bar'; first: 10 ]
On Aug 25, 2007, at 7:35 PM, leves@elte.hu wrote:
pipe: aBlock
| catcher pipedObject | catcher := MessageCatcher new privAccumulator: OrderedCollection new. aBlock value: catcher. pipedObject := self. catcher privAccumulator do: [ :each | pipedObject := each sendTo: pipedObject ]. ^pipedObject
Thanks leves ... :-) ...! You rock ! I didn't know about the MessageCatcher.
Really really close .... as this fails.
| collection | collection := OrderedCollection new. collection add:10; add:20; add:30. 10 pipe: [:item | item + 1 ; + 1; > 10 ; ifTrue: [#True] ifFalse: [#False] <- No special messages expected ->]
Fabio
On Sun, 26 Aug 2007, Fabio Filasieno wrote:
Thanks leves ... :-) ...! You rock ! I didn't know about the MessageCatcher.
Really really close .... as this fails.
| collection | collection := OrderedCollection new. collection add:10; add:20; add:30. 10 pipe: [:item | item + 1 ; + 1; > 10 ; ifTrue: [#True] ifFalse: [#False] <- No special messages expected ->]
Fabio
Some messages can not be cascaded, and special messages like #ifTrue:ifFalse: can not be catched by MessageCatcher. I don't know if other smalltalks have the same behavior, or not. If MessageCatcher could catch messages like #ifTrue:ifFalse:, then one could simply use the following workaround, even if the message can't be cascaded:
10 pipe: [:item | item + 1 ; + 1; > 10. item ifTrue: [#True] ifFalse: [#False] ] (I know it breaks the "pipe theory" :))
Levente
But of course you can write your own version of a conditional that will work fine ....
Cheers,
Alan
-----------
At 09:09 AM 8/26/2007, UZONYI Levente wrote:
On Sun, 26 Aug 2007, Fabio Filasieno wrote:
Thanks leves ... :-) ...! You rock ! I didn't know about the MessageCatcher.
Really really close .... as this fails.
| collection | collection := OrderedCollection new. collection add:10; add:20; add:30. 10 pipe: [:item | item + 1 ; + 1; > 10 ; ifTrue: [#True] ifFalse: [#False] <- No special messages expected ->]
Fabio
Some messages can not be cascaded, and special messages like #ifTrue:ifFalse: can not be catched by MessageCatcher. I don't know if other smalltalks have the same behavior, or not. If MessageCatcher could catch messages like #ifTrue:ifFalse:, then one could simply use the following workaround, even if the message can't be cascaded:
10 pipe: [:item | item + 1 ; + 1; > 10. item ifTrue: [#True] ifFalse: [#False] ] (I know it breaks the "pipe theory" :))
Levente
squeak-dev@lists.squeakfoundation.org