----- 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