diff options
Diffstat (limited to 'ruby/step9_interop.rb')
| -rw-r--r-- | ruby/step9_interop.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/ruby/step9_interop.rb b/ruby/step9_interop.rb index 869a86d..ba35146 100644 --- a/ruby/step9_interop.rb +++ b/ruby/step9_interop.rb @@ -133,18 +133,16 @@ end repl_env = Env.new RE = lambda {|str| EVAL(READ(str), repl_env) } REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } -_ref = lambda {|k,v| repl_env.set(k, v) } -# Import core functions -$core_ns.each &_ref +# core.rb: defined using ruby +$core_ns.each do |k,v| repl_env.set(k,v) end +repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) -_ref[:"read-string", lambda {|str| read_str str}] -_ref[:eval, lambda {|ast| EVAL(ast, repl_env)}] -_ref[:slurp, lambda {|f| File.read(f) }] - -# Defined using the language itself +# core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] +RE["(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"] +RE["(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"] if ARGV.size > 0 ARGV.each {|f| |
