[squeak-dev] A little puzzle
Stéphane Rollandin
lecteur at zogotounga.net
Thu May 14 19:11:26 UTC 2015
Hmm, now I see that my last idea does not work if I want to reuse the
block...
| block |
block := (Puzzle new blockIterating: (1 to: 5)) value: [ ^self].
block value: [:p | Transcript show: p; cr] value: [:p | p < 3].
block value: [:p | Transcript show: p; cr] value: [:p | p < 4].
This stops after
1
2
while your implementation works fine: the Transcript shows
1
2
1
2
3
indeed.
Stef
> Ah, so that's the bottom line. Thanks a lot ! I'm now trying to wrap my
> head around these concepts...
>
> It looks like I could also get the return block as an outside argument,
> like this:
>
>
> Puzzle>>blockIterating: aCollection
>
> ^ [:returnBlock |
> [:doBlock :whileBlock |
> aCollection do: [:i |
> (whileBlock value: i) ifFalse: returnBlock.
> doBlock value: i]]].
>
>
> and then use it as follow:
>
>
> | block |
>
> block := (Puzzle new blockIterating: (1 to: 5)) value: [ ^self].
>
> block value: [:p | Transcript show: p; cr] value: [:p | p < 3]
>
>
> A bit hard to read but it seems to work. Does that make sense ?
More information about the Squeak-dev
mailing list
|