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!


Gmane