Hi all,<br><br>If I write the following code to experiment with squeak's block closures I get the expected answer:<br>factorial := [:n | (n=1) ifTrue: [1] ifFalse: [n * (factorial value: (n - 1))]].<br>factorial 3. -> 6<br>
<br>In this case it appears that the block is implicitly returning the last object, ie: return 1 in the ifTrue: case. If I change the code to explicitly return the 1 ie:<br>factorial := [:n | (n=1) ifTrue: [^1] ifFalse: [n * (factorial value: (n - 1))]].<br>
factorial 3. -> An error indicating that the block cannot return.<br><br>My question is this: Why is the implicit return of values allowed and not the explicit? Is there a best practice for dealing with block closures in smalltalk, such that we should only be using implicit returns?<br>
<br>Thanks for your help,<br>Jeff G.<br>