On Wed, 09 Aug 2006 21:11:40 +0200, Ron Teitelbaum wrote:
Brian,

Yes I agree it's a great suggestion, although a few changes:
Literal blocks to not parse into collections automatically.

Ron, please: a literal Array is a subclass of Collection and so the blocks in

 { [nil]. [true]. [false] }

parse "into collections automatically". You didn't inspectIt for verifying your (false) claim, didn't you. Also, have a look at the implementors of #caseOf: and #caseOf:otherwise:, they are heavy users of literal blocks in Collections ...

...
Each in this case is already a block.

Yes. And, into the other direction, even in good core methods one often finds things like

 ^ dict at: aKey ifAbsent: [nil]

There seems to be a "natural" confusion between "object" value and block "value". Not a big surprise since Java and other procedural-oriented friends do not offer block values. So any demo of using blocks "as if" they where any other object, as Brian has shown, is a sign for the ability to master the subject 8-)

Only each is needed.

Absolutely.

So here is a version that works.

(OrderedCollection new
add: [10/0];
add: [2 raisedToInteger: 1/2];
add: [-5 raisedTo: 1.5]; yourself
) do: [:each | each on: Exception do: [:ex | Transcript show: ex; cr;
endEntry]].

endEntry is for Klaus!

Hhm, endEntry is too expensive within any and every loop. Just put Transcript endEntry after the loop. I mentioned endEntry because Transcript almost always does not display the last lines (they are buffered) and people get confused and believe that either their code or Squeak is wrong (but both is not the case).

It is a very good suggestion Brian!

Indeed, and Briant's use of literal blocks in a literal Array is perfect (in the sense of: cannot be made better).

/Klaus

Ron Teitelbaum

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to