Pierre Thibault | 20 Jul 08:28

[groovy-user] Recursivity bug with closure?

Hello,

I think that I found a recursivity bug with closure. This code does not work:

def factoriel = { int v ->
    if (v == 0) {
        return 1
    } else {
        return v*this.factoriel(v-1)
    }
}

println factoriel(5)

But this work well:

def factoriel(int v) {
    if (v == 0) {
        return 1
    } else {
        return v*this.factoriel(v-1)
    }
}

println factoriel(5)

I've tried with Groovy 1.5.5 and 1.5.6.

Any idea?

Pierre


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

Guillaume Laforge | 20 Jul 10:38
Gravatar

Re: [groovy-user] Recursivity bug with closure?

Hi Pierre,

This is because you can't call a closure that hasn't been defined first.
def factoriel
factoriel = { ... }
In that case you'd be able to call factoriel() directly inside the
closure, as it's been defined before use.

On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33@...> wrote:
> Hello,
>
> I think that I found a recursivity bug with closure. This code does not
> work:
>
> def factoriel = { int v ->
>     if (v == 0) {
>         return 1
>     } else {
>         return v*this.factoriel(v-1)
>     }
> }
>
> println factoriel(5)
>
> But this work well:
>
> def factoriel(int v) {
>     if (v == 0) {
>         return 1
>     } else {
>         return v*this.factoriel(v-1)
>     }
> }
>
> println factoriel(5)
>
> I've tried with Groovy 1.5.5 and 1.5.6.
>
> Any idea?
>
> ________________________________
> Pierre
>
>
> ________________________________
>
> Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your
> favourite sites. Download it now!

--

-- 
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Jose Noheda | 20 Jul 19:23

Re: [groovy-user] Recursivity bug with closure?

Is this discouraged for some reason?

def factoriel = { int v ->
    if (v == 0) {
        return 1
    } else {
        return v * call(v-1)
    }
}

println factoriel(5)

Regards,

On Sun, Jul 20, 2008 at 10:38 AM, Guillaume Laforge <glaforge-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi Pierre,

This is because you can't call a closure that hasn't been defined first.
def factoriel
factoriel = { ... }
In that case you'd be able to call factoriel() directly inside the
closure, as it's been defined before use.

On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33-FFYn/CNdgSA@public.gmane.org> wrote:
> Hello,
>
> I think that I found a recursivity bug with closure. This code does not
> work:
>
> def factoriel = { int v ->
>     if (v == 0) {
>         return 1
>     } else {
>         return v*this.factoriel(v-1)
>     }
> }
>
> println factoriel(5)
>
> But this work well:
>
> def factoriel(int v) {
>     if (v == 0) {
>         return 1
>     } else {
>         return v*this.factoriel(v-1)
>     }
> }
>
> println factoriel(5)
>
> I've tried with Groovy 1.5.5 and 1.5.6.
>
> Any idea?
>
> ________________________________
> Pierre
>
>
> ________________________________
>
> Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your
> favourite sites. Download it now!



--
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Guillaume Laforge | 20 Jul 20:06
Gravatar

Re: [groovy-user] Recursivity bug with closure?

Not really, you can also do that.

On Sun, Jul 20, 2008 at 7:23 PM, Jose Noheda <jose.noheda@...> wrote:
> Is this discouraged for some reason?
>
> def factoriel = { int v ->
>     if (v == 0) {
>         return 1
>     } else {
>         return v * call(v-1)
>     }
> }
>
> println factoriel(5)
>
> Regards,
>
> On Sun, Jul 20, 2008 at 10:38 AM, Guillaume Laforge <glaforge@...>
> wrote:
>>
>> Hi Pierre,
>>
>> This is because you can't call a closure that hasn't been defined first.
>> def factoriel
>> factoriel = { ... }
>> In that case you'd be able to call factoriel() directly inside the
>> closure, as it's been defined before use.
>>
>> On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33@...>
>> wrote:
>> > Hello,
>> >
>> > I think that I found a recursivity bug with closure. This code does not
>> > work:
>> >
>> > def factoriel = { int v ->
>> >     if (v == 0) {
>> >         return 1
>> >     } else {
>> >         return v*this.factoriel(v-1)
>> >     }
>> > }
>> >
>> > println factoriel(5)
>> >
>> > But this work well:
>> >
>> > def factoriel(int v) {
>> >     if (v == 0) {
>> >         return 1
>> >     } else {
>> >         return v*this.factoriel(v-1)
>> >     }
>> > }
>> >
>> > println factoriel(5)
>> >
>> > I've tried with Groovy 1.5.5 and 1.5.6.
>> >
>> > Any idea?
>> >
>> > ________________________________
>> > Pierre
>> >
>> >
>> > ________________________________
>> >
>> > Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark
>> > your
>> > favourite sites. Download it now!
>>
>>
>>
>> --
>> Guillaume Laforge
>> Groovy Project Manager
>> G2One, Inc. Vice-President Technology
>> http://www.g2one.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

--

-- 
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Pierre Thibault | 20 Jul 14:30

Re: [groovy-user] Recursivity bug with closure?

Yes, this is true. I remember now... The closure is defined at run time only.

Thank you.

----- Original Message ----
From: Guillaume Laforge <glaforge-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
Sent: Sunday, July 20, 2008 4:38:14 AM
Subject: Re: [groovy-user] Recursivity bug with closure?

Hi Pierre,

This is because you can't call a closure that hasn't been defined first.
def factoriel
factoriel = { ... }
In that case yo u'd be able to call factoriel() directly inside the
closure, as it's been defined before use.

On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33-FFYn/CNdgSA@public.gmane.org> wrote:
> Hello,
>
> I think that I found a recursivity bug with closure. This code does not
> work:
>
> def factoriel = { int v ->
>    if (v == 0) {
>        return 1
>    } else {
>        return v*this.factoriel(v-1)
>    }
> }
>
> println factoriel(5)
>
> But this work well:
>
> def factoriel(int v) {
>    if (v == 0) {
>        return 1
>    } else {
>        return v*this.factoriel(v-1)
>    }
> }
>
> println factoriel(5)
>
> I've tried with Groovy 1.5.5 and 1.5.6.
>
> Any idea?
>
> ________________________________
> Pierre
>
>
> ________________________________
>
> Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your
> favourite sites. Download it now!



--
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Instant message from any web browser! Try the new Yahoo! Canada Messenger for the Web BETA
Pierre Thibault | 20 Jul 20:54

Re: [groovy-user] Recursivity bug with closure?

What is the subject of 'call'? 'this.call' does not work.

Pierre

----- Original Message ----
From: Guillaume Laforge <glaforge-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: user-i9PBDF1N6cxnkHa44VUL00B+6BGkLq7r@public.gmane.org
Sent: Sunday, July 20, 2008 2:06:52 PM
Subject: Re: [groovy-user] Recursivity bug with closure?

Not really, you can also do that.

On Sun, Jul 20, 2008 at 7:23 PM, Jose Noheda <jose.noheda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Is this discouraged for some reason?
>
> def factoriel = { int v ->
>    if (v == 0) {
>        return 1
>    } else {
>        return v * call(v-1)
>    }
> }
>
> println factoriel(5)
>
> Regards,
>
> On Sun, Jul 20, 2008 at 10:38 AM, Guillaume Laforge <glaforge-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>>
>> Hi Pierre,
>>
>> This is because you can't call a closure that hasn't been defined first.
>> def factoriel
>> factoriel = { ... }
>> In that case you'd be able to call factoriel() directly inside the
>> closure, as it's been defined before use.
>>
> > On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33-FFYn/CNdgSA@public.gmane.org>
>> wrote:
>> > Hello,
>> >
>> > I think that I found a recursivity bug with closure. This code does not
>> > work:
>> >
>> > def factoriel = { int v ->
>> >    if (v == 0) {
>> >        return 1
>> >    } else {
>> >        return v*this.factoriel(v-1)
>> >    }
>> > }
>> >
>> > println factoriel(5)
>> >
>> > But this work well:
>> >
>> > def factoriel(int v) {
>> >    if (v == 0) {
>> >        return 1
>> >    } else {
>> >        return v*this.factoriel(v-1)
>> >    }
>> > }
>> >
>> > println factoriel(5)
>> >
>> > I've tried with Groovy 1.5.5 and 1.5.6.
>> >
>> > Any idea?
>> >
>> > ________________________________
>> > Pierre
>> >
>> >
>> > ________________________________
>> >
>> > Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark
>> > your
>> > favourite sites. Download it now!
>>
>>
>>
>> --
>> Guillaume Laforge
>> Groovy Project Manager
>> G2One, Inc. Vice-President Technology
>> http://www.g2one.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   
http://xircles.codehaus.org/manage_email
>>
>>
>
>



--
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reclaim your name <at> ymail.com or <at> rocketmail.com. Get your new email address now!
Guillaume Laforge | 20 Jul 21:08
Gravatar

Re: [groovy-user] Recursivity bug with closure?

call() is a method on closure which 'calls' the closure.
For instance, when you call a closure, you usually do myClosure(),
which is a shortcut for myClosure.call()

On Sun, Jul 20, 2008 at 8:59 PM, Pierre Thibault <pthibault33@...> wrote:
> What is the subject of 'call'? 'this.call' does not work.
>
> ________________________________
> Pierre
>
> ----- Original Message ----
> From: Guillaume Laforge <glaforge@...>
> To: user@...
> Sent: Sunday, July 20, 2008 2:06:52 PM
> Subject: Re: [groovy-user] Recursivity bug with closure?
>
> Not really, you can also do that.
>
> On Sun, Jul 20, 2008 at 7:23 PM, Jose Noheda <jose.noheda@...> wrote:
>> Is this discouraged for some reason?
>>
>> def factoriel = { int v ->
>>    if (v == 0) {
>>        return 1
>>    } else {
>>        return v * call(v-1)
>>    }
>> }
>>
>> println factoriel(5)
>>
>> Regards,
>>
>> On Sun, Jul 20, 2008 at 10:38 AM, Guillaume Laforge <glaforge@...>
>> wrote:
>>>
>>> Hi Pierre,
>>>
>>> This is because you can't call a closure that hasn't been defined first.
>>> def factoriel
>>> factoriel = { ... }
>>> In that case you'd be able to call factoriel() directly inside the
>>> closure, as it's been defined before use.
>>>
>>> On Sun, Jul 20, 2008 at 8:32 AM, Pierre Thibault <pthibault33@...>
>>> wrote:
>>> > Hello,
>>> >
>>> > I think that I found a recursivity bug with closure. This code does not
>>> > work:
>>> >
>>> > def factoriel = { int v ->
>>> >    if (v == 0) {
>>> >        return 1
>>> >    } else {
>>> >        return v*this.factoriel(v-1)
>>> >    }
>>> > }
>>> >
>>> > println factoriel(5)
>>> >
>>> > But this work well:
>>> >
>>> > def factoriel(int v) {
>>> >    if (v == 0) {
>>> >        return 1
>>> >    } else {
>>> >        return v*this.factoriel(v-1)
>>> >    }
>>> > }
>>> >
>>> > println factoriel(5)
>>> >
>>> > I've tried with Groovy 1.5.5 and 1.5.6.
>>> >
>>> > Any idea?
>>> >
>>> > ________________________________
>>> > Pierre
>>> >
>>> >
>>> > ________________________________
>>> >
>>> > Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark
>>> > your
>>> > favourite sites. Download it now!
>>>
>>>
>>>
>>> --
>>> Guillaume Laforge
>>> Groovy Project Manager
>>> G2One, Inc. Vice-President Technology
>>> http://www.g2one.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>
>
>
> --
> Guillaume Laforge
> Groovy Project Manager
> G2One, Inc. Vice-President Technology
> http://www.g2one.com
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>
> ________________________________
> Reclaim your name @ymail.com or @rocketmail.com. Get your new email address
> now!

--

-- 
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane