20 Jul 08:28
[groovy-user] Recursivity bug with closure?
From: Pierre Thibault <pthibault33@...>
Subject: [groovy-user] Recursivity bug with closure?
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-20 06:32:15 GMT
Subject: [groovy-user] Recursivity bug with closure?
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-20 06:32:15 GMT
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
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
Here is a script that demonstrates trying to find them in the script's
class methods and metaClass methods:
public class MyMagicCategory {
static def whereDoILive( Script self ) {
println "Hello. I'm right here."
}
}
use (MyMagicCategory) {
whereDoILive()
def foundInMethods = this.class.methods.find{ it.name ==
"doSomething" } != null
def foundInMetaMethods = this.metaClass.metaMethods.find{ it.name
== "doSomething" } != null
assert foundInMethods || foundInMetaMethods
}
Output:
Hello. I'm right here.
Exception thrown: java.lang.AssertionError: Expression:
(foundInMethods || foundInMetaMethods). Values: foundInMethods =
false, foundInMetaMethods = false
java.lang.AssertionError: Expression: (foundInMethods ||
foundInMetaMethods). Values: foundInMethods = false,
foundInMetaMethods = false
at Script15$_run_closure1.doCall(Script15:14)
at Script15$_run_closure1.doCall(Script15)
at Script15.run(Script15:9)
Thanks for the help!
--
Jason
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
RSS Feed