groovyshell - recursion not working in groovy -


i have following piece of code

def normalfactorial = { biginteger n -> n <= 1 ? 1 : normalfactorial(n - 1) * n }  println normalfactorial(1) println normalfactorial(2) 

normalfactorial(1) method works fine , prints 1 expected. second call fails below exception. clues.. ????

may 09, 2013 10:39:23 pm org.codehaus.groovy.runtime.stacktraceutils sanitize  warning: sanitizing stacktrace:  groovy.lang.missingmethodexception: no signature of method: tailrecursion.normalfactorial() applicable argument types: (java.math.biginteger) values: [1]      @ org.codehaus.groovy.runtime.scriptbytecodeadapter.unwrap(scriptbytecodeadapter.java:55) 

the closure isn't defined when define closure (if makes sense)

try:

def normalfactorial normalfactorial = { biginteger n ->   n <= 1 ? 1 : normalfactorial(n - 1) * n } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -