Block recursion in Dolphin.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Block recursion in Dolphin.

Costas Menico-2
Hi,

The output should have printed the values for 'i' backwards. Instead
it prints 0s for the following code.

recurseblock:=[ :i |
        i > 0 ifTrue: [ recurseblock value: ( i - 1)].
        Transcript show:  i printString; cr
        ].

recurseblock value: 4.

It seems Dolphin does not preserve the block parameters in a recursive
situation, Is this the way Dolphin behaves or is it a bug? What do
other Smalltalks do? (Squeak doesn't even allow this)

Thanks

Costas


Reply | Threaded
Open this post in threaded view
|

Re: Block recursion in Dolphin.

Boris Popov
VisualWorks prints ->

******
0
1
2
3
4
******

Boris

"Costas Menico" <[hidden email]> wrote in message
news:[hidden email]...

> Hi,
>
> The output should have printed the values for 'i' backwards. Instead
> it prints 0s for the following code.
>
> recurseblock:=[ :i |
> i > 0 ifTrue: [ recurseblock value: ( i - 1)].
> Transcript show:  i printString; cr
> ].
>
> recurseblock value: 4.
>
> It seems Dolphin does not preserve the block parameters in a recursive
> situation, Is this the way Dolphin behaves or is it a bug? What do
> other Smalltalks do? (Squeak doesn't even allow this)
>
> Thanks
>
> Costas
>


Reply | Threaded
Open this post in threaded view
|

Re: Block recursion in Dolphin.

Ian Bartholomew
In reply to this post by Costas Menico-2
Costas,

> It seems Dolphin does not preserve the block parameters in a recursive
> situation, Is this the way Dolphin behaves or is it a bug? What do
> other Smalltalks do? (Squeak doesn't even allow this)

Yes, that is the way that Dolphin behaves as it does not support full block
closures. This has been discussed a number of times before in the newsgroup,
usually in the context of blocks retaining references to arguments and
variables, so a search through the archive should help.

Basically, rather than creating a new block context on each recursive stage
Dolphin just reuses the initial block context. This argument stored within
this context is then overwritten on each recursion and the final value, set
when the initial test fails, is the value you see printed on the Transcript
as the recursion unwinds.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Block recursion in Dolphin.

Ricardo Nogueira
In reply to this post by Costas Menico-2
Hi Costas,

This the issue of true closures:
As far as I know Dolphin doesn't implement block with local variables (but
reuses the block context). VW and VA do have true block closures, though.

A search with Ian's news browser on "recursive blocks" or "true closures"
may reveal what was posted here before.

All the best,

RiNo
[hidden email]


"Costas Menico" <[hidden email]> wrote in message
news:[hidden email]...

> Hi,
>
> The output should have printed the values for 'i' backwards. Instead
> it prints 0s for the following code.
>
> recurseblock:=[ :i |
> i > 0 ifTrue: [ recurseblock value: ( i - 1)].
> Transcript show:  i printString; cr
> ].
>
> recurseblock value: 4.
>
> It seems Dolphin does not preserve the block parameters in a recursive
> situation, Is this the way Dolphin behaves or is it a bug? What do
> other Smalltalks do? (Squeak doesn't even allow this)
>
> Thanks
>
> Costas
>