[squeak-dev] #valueWithExit inconsistency (?)

Jaromir m at jaromir.net
Wed Feb 17 19:17:44 UTC 2021


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


More information about the Squeak-dev mailing list