aboutsummaryrefslogtreecommitdiff
path: root/ruby/step9_interop.rb
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-23 21:59:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-23 21:59:50 -0500
commit6301e0b6374cecc5599665be14d6ddc6a31ce1e8 (patch)
treedbf1dc2ff6c682fd87c72a7907e7f6e59c8d4c03 /ruby/step9_interop.rb
parent89bd4de1e2704c1bc562788b2c5e4fc08b71a538 (diff)
downloadmal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.tar.gz
mal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.zip
All: TCO let* and quasiquote.
Diffstat (limited to 'ruby/step9_interop.rb')
-rw-r--r--ruby/step9_interop.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/ruby/step9_interop.rb b/ruby/step9_interop.rb
index 507114e..6d2cbe2 100644
--- a/ruby/step9_interop.rb
+++ b/ruby/step9_interop.rb
@@ -83,11 +83,12 @@ def EVAL(ast, env)
a1.each_slice(2) do |a,e|
let_env.set(a, EVAL(e, let_env))
end
- return EVAL(a2, let_env)
+ env = let_env
+ ast = a2 # Continue loop (TCO)
when :quote
return a1
when :quasiquote
- return EVAL(quasiquote(a1), env)
+ ast = quasiquote(a1); # Continue loop (TCO)
when :defmacro!
func = EVAL(a2, env)
func.is_macro = true
@@ -98,14 +99,14 @@ def EVAL(ast, env)
return eval(a1)
when :do
eval_ast(ast[1..-2], env)
- ast = ast.last
+ ast = ast.last # Continue loop (TCO)
when :if
cond = EVAL(a1, env)
if not cond
return nil if a3 == nil
- ast = a3
+ ast = a3 # Continue loop (TCO)
else
- ast = a2
+ ast = a2 # Continue loop (TCO)
end
when :"fn*"
return Function.new(a2, env, a1) {|*args|
@@ -116,7 +117,7 @@ def EVAL(ast, env)
f = el[0]
if f.class == Function
ast = f.ast
- env = f.gen_env(el.drop(1))
+ env = f.gen_env(el.drop(1)) # Continue loop (TCO)
else
return f[*el.drop(1)]
end