...
| Code Block |
|---|
// requires jython and jython-engine jars
engine = mgr.getEngineByName("jython")
engine.eval('''
def factorial(n):
i=fact=1
while i <= n:
fact=fact*i
i=i+1
return fact
result = factorial(4)
''')
println 'jython: ' + engine.result
|
Or Clojure:
| Code Block |
|---|
// requires clojure and clojure-engine jars
// Note: doesn't seem officially supported, hacked a version from here:
// http://wiki.github.com/pmf/clojure-jsr223
engine = mgr.getEngineByName("clojure")
println 'clojure: ' + engine.eval('''
(defn factorial [n]
(if (< n 2)
1
(* n (factorial (- n 1)))))
(factorial 4)
''')
|
Or Jaskell:
| Code Block |
|---|
// requires jaskell and jaskell engine and jparsec and jfunutil jars
engine = mgr.getEngineByName("jaskell")
engine.eval('factorial n = if n > 0 then n * factorial (n-1) else 1')
println 'jaskell: ' + engine.eval('factorial 4')
|
...
| No Format |
|---|
javascript: 24.0
jruby: 24
jython: 24
clojure: 24
jaskell: 24
|
See also: Accessing Groovy from Java via JSR-223