Esempio n. 1
0
 def lazilyLoadGamerStub(self):
     """ generated source for method lazilyLoadGamerStub """
     if self.theClojureGamer == None:
         try:
             #  Load the Clojure script -- as a side effect this initializes the runtime.
             RT.loadResourceScript(self.getClojureGamerFile() + ".clj")
             #  Get a reference to the gamer-generating function.
             #  Call it!
             self.theClojureGamer = gamerVar.invoke()
         except Exception as e:
             GamerLogger.logError("GamePlayer", "Caught exception in Clojure initialization:")
             GamerLogger.logStackTrace("GamePlayer", e)
Esempio n. 2
0
def build_clojure_function_object(clj_namespace, fn):
    """Builds a clojure function from a python function with clojure code in the docs.
    """
    clojure_code = "(ns %s (:use [overtone.live] [fortissimo.instruments]))\n%s" % (clj_namespace, fn.__doc__)
    clojure_compile_string(clojure_code)
    clojure_fnc = RT.var(clj_namespace, fn.func_name)
    return clojure_fnc
Esempio n. 3
0
def build_clojure_function_object(clj_namespace, fn):
    """Builds a clojure function from a python function with clojure code in the docs.
    """
    clojure_code = '(ns %s)\n%s' % (
        clj_namespace,
        fn.__doc__)
    clojure_compile_string(clojure_code)
    clojure_fnc = RT.var(clj_namespace, fn.func_name)
    return clojure_fnc
Esempio n. 4
0
def init():
    cl = IJ.getClassLoader()
    if cl is not None:
        Thread.currentThread().setContextClassLoader(cl)
    print "init", cl
    ns = RT.var("clojure.core", "*ns*")
    warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*")
    unchecked_math = RT.var("clojure.core", "*unchecked-math*")
    compile_path = RT.var("clojure.core", "*compile-path*")
    Var.pushThreadBindings(ns, ns.get(), warn_on_reflection,
                           warn_on_reflection.get(), unchecked_math,
                           unchecked_math.get(), compile_path, "classes")
    in_ns = RT.var("clojure.core", "in-ns")
    refer = RT.var("clojure.core", "refer")
    in_ns.invoke(Symbol.intern("user"))
    refer.invoke(Symbol.intern("clojure.core"))
Esempio n. 5
0
from clojure.lang import RT, Compiler
import java.io

Compiler.load(java.io.StringReader("(println 'foo)"))

source = '''
(ns rember)

(defn rember [a lat]
  (cond
   (empty? lat) '()
   (= (first lat) a) (rest lat)
   :else (cons
          (first lat)
          (rember a (rest lat)))))
'''

Compiler.load(java.io.StringReader(source))

rember = RT.var('rember', 'rember')
print rember.invoke(2, range(4))