diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-27 23:49:55 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-06 21:59:01 -0600 |
| commit | fb5c165838a658c79c9772c264a0a1673bc5081b (patch) | |
| tree | 648af704e93cad3369401d871a0e5ae0169f2860 /ruby | |
| parent | b554fd4ed035396886c673778d60659085d8b286 (diff) | |
| download | mal-fb5c165838a658c79c9772c264a0a1673bc5081b.tar.gz mal-fb5c165838a658c79c9772c264a0a1673bc5081b.zip | |
go: add time-ms. Ruby: fix step9,A content.
Diffstat (limited to 'ruby')
| -rw-r--r-- | ruby/step9_try.rb | 2 | ||||
| -rw-r--r-- | ruby/stepA_interop.rb | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/ruby/step9_try.rb b/ruby/step9_try.rb index 6123293..eecba9c 100644 --- a/ruby/step9_try.rb +++ b/ruby/step9_try.rb @@ -95,8 +95,6 @@ def EVAL(ast, env) return env.set(a1, func) when :macroexpand return macroexpand(a1, env) - when :"rb*" - return eval(a1) when :"try*" begin return EVAL(a1, env) diff --git a/ruby/stepA_interop.rb b/ruby/stepA_interop.rb index 6d2cbe2..6123293 100644 --- a/ruby/stepA_interop.rb +++ b/ruby/stepA_interop.rb @@ -97,6 +97,21 @@ def EVAL(ast, env) return macroexpand(a1, env) when :"rb*" return eval(a1) + when :"try*" + begin + return EVAL(a1, env) + rescue Exception => exc + if exc.is_a? MalException + exc = exc.data + else + exc = exc.message + end + if a2 && a2[0] == :"catch*" + return EVAL(a2[2], Env.new(env, [a2[1]], [exc])) + else + raise esc + end + end when :do eval_ast(ast[1..-2], env) ast = ast.last # Continue loop (TCO) @@ -142,6 +157,7 @@ repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself +RE["(def! *host-language* \"ruby\")"] 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)))))))"] @@ -153,6 +169,7 @@ if ARGV.size > 0 end # repl loop +RE["(println (str \"Mal [\" *host-language* \"]\"))"] while line = _readline("user> ") begin puts REP[line] |
