aboutsummaryrefslogtreecommitdiff
path: root/ruby/step6_file.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/step6_file.rb
parent89bd4de1e2704c1bc562788b2c5e4fc08b71a538 (diff)
downloadmal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.tar.gz
mal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.zip
All: TCO let* and quasiquote.
Diffstat (limited to 'ruby/step6_file.rb')
-rw-r--r--ruby/step6_file.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/ruby/step6_file.rb b/ruby/step6_file.rb
index 191febe..0c99cee 100644
--- a/ruby/step6_file.rb
+++ b/ruby/step6_file.rb
@@ -48,17 +48,18 @@ 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 :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|
@@ -69,7 +70,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