Ejemplo n.º 1
0
def parse(code):
    EOF = Object()
    ret = None
    thread = Thread.currentThread()
    # Evaluate all tokens in code, one by one
    while not thread.isInterrupted():
        r = LispReader.read(LineNumberingPushbackReader(StringReader(code)),
                            False, EOF, False)
        if EOF == r:
            break
        ret = Compiler.eval(r)
    # Return the result of evaluating the last token
    return ret
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
def clojure_compile_string(clojure_code):
    """Compile the clojure_code with clojure compiler
    """
    Compiler.load(java.io.StringReader(clojure_code))