Current implementation of #valueWithExit seems a bit inconsistent in its
return value: it returns either nil (if the receiver exited using the exit block) or the receiver. Would it be worth modifying it to always return nil? (there are no senders anyway) valueWithExit - self value: [ ^nil ] + ^self value: [ ^nil ] Or using a nice complementary method #valueWithExit: valueWithExit: aBlock self value: [^aBlock value]. ^aBlock value valueWithExit ^self valueWithExit: [nil] Thanks ----- Jaromir ^[^ -- Sent from: http://forum.world.st/Squeak-Dev-f45488.html
^[^ Jaromir
|
Hi Jaromir. I added commentary via Kernel-mt.1370. I don't think that the (outer block's) return value should ever be used in this construct. It is more like a #detect: but without meaningful return values. http://forum.world.st/explicit-return-from-a-block-tp51833.html http://forum.world.st/The-Trunk-Kernel-ul-519-mcz-td3077583.html I don't suppose it is idiomatic Smalltalk: "...but actually, I never had any reason to use this except when porting algorithms from Fortran or C... " Best, Marcel
|
On Wed, Feb 17, 2021 at 8:52 AM Marcel Taeumel <[hidden email]> wrote:
But there's a bug. It should at least answer the result of value:. I'm going to change it.
_,,,^..^,,,_ best, Eliot |
Hi, thanks for your feedback! I'm by no means advocating for using returns
from blocks :) I just found it useful in understanding the local vs. non-local returns... e.g. in this example the return value is useful: "find max value before nil and return its square" | supplier max maxSquared | supplier := {3 . 2 . 5 . 1 . nil . 6} readStream. maxSquared := [:exitBlock | | value | max := 0. [supplier atEnd] whileFalse: [ value := supplier next. value ifNil: [exitBlock value]. max := max max: value] ] valueWithExit: [max squared]. "more code" Transcript show: maxSquared ----- Jaromir ^[^ -- Sent from: http://forum.world.st/Squeak-Dev-f45488.html
^[^ Jaromir
|
Free forum by Nabble | Edit this page |