That's intersting.
I assume you mean that Dolphin resulted in this output: 0 0 0 0 0
In Dolphin I would expect that the variable #i for this block is bound within the context of the UndefinedObject>>DoIt method (or whatever they use). Since the last value bound to #i is 0, all 0's would be displayed as the recursive calls unwind.
You should try this code and see the result: recurseblock:=[ :i | Transcript show: i printString; cr. i > 0 ifTrue: [ recurseblock value: ( i - 1)]. Transcript show: i printString; cr. ].
In my opinion it is hard to call this a bug except maybe that they let you do it at all. Blocks and their arguments are really not so independent but are always a part of the context of its parent method call context. (I hope I said that right.)
Of course recursive methods work fine in Squeak. If you define on Object class the following method: recursiveCallTest: i i > 0 ifTrue: [ self recursiveCallTest: ( i - 1)]. Transcript show: i printString; cr.
And then execute: Object recursiveCallTest: 4.
You will get the expected result in the transcript: 0 1 2 3 4
Gnu Smalltalk is intersting because it accepts recursive blocks in the way you were expecting. I executed this code: Smalltalk at: #RB put: [ :i | i > 0 ifTrue: [ (Smalltalk at: #RB) value: ( i - 1)]. stdout nextPutAll: i printString; nextPut: Character nl ]! (Smalltalk at: #RB) value: 4!
And got the resulting transcript listed below.
Cheers, Jon
--------------------------------------------------------------- GNU Smalltalk Ready
st> Smalltalk at: #RB put: [ :i | st> i > 0 ifTrue: [ (Smalltalk at: #RB) value: ( i - 1)]. st> stdout nextPutAll: i printString; nextPut: Character nl ]!
Execution begins... 213 byte codes executed which took 0.001 seconds, giving 213000 bytecodes/sec 22 primitives, percent 10.33 self returns 0, inst var returns 2, literal returns 0 41 samples since last cache cleanup, percent 19.25 12 cache hits, 29 misses, 29.27 percent hits returned value is nil st> (Smalltalk at: #RB) value: 4!
Execution begins... 0 1 2 3 4 2383 byte codes executed which took 0.001 seconds, giving 2383000 bytecodes/sec 177 primitives, percent 7.43 self returns 20, inst var returns 10, literal returns 10 370 samples since last cache cleanup, percent 15.53 316 cache hits, 54 misses, 85.41 percent hits returned value is nil st>
squeak-dev@lists.squeakfoundation.org