aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/step5_tco.py4
-rw-r--r--python/step6_file.py4
-rw-r--r--python/step7_quote.py7
-rw-r--r--python/step8_macros.py7
-rw-r--r--python/step9_interop.py7
-rw-r--r--python/stepA_more.py7
6 files changed, 26 insertions, 10 deletions
diff --git a/python/step5_tco.py b/python/step5_tco.py
index 72457e9..cbb92c9 100644
--- a/python/step5_tco.py
+++ b/python/step5_tco.py
@@ -45,7 +45,9 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "do" == a0:
eval_ast(ast[1:-1], env)
ast = ast[-1]
diff --git a/python/step6_file.py b/python/step6_file.py
index 764eb53..9d84d1f 100644
--- a/python/step6_file.py
+++ b/python/step6_file.py
@@ -45,7 +45,9 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "do" == a0:
eval_ast(ast[1:-1], env)
ast = ast[-1]
diff --git a/python/step7_quote.py b/python/step7_quote.py
index 1002613..de19c6d 100644
--- a/python/step7_quote.py
+++ b/python/step7_quote.py
@@ -63,11 +63,14 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "quote" == a0:
return ast[1]
elif "quasiquote" == a0:
- return EVAL(quasiquote(ast[1]), env)
+ ast = quasiquote(ast[1]);
+ # Continue loop (TCO)
elif "do" == a0:
eval_ast(ast[1:-1], env)
ast = ast[-1]
diff --git a/python/step8_macros.py b/python/step8_macros.py
index 28b68fb..80ca239 100644
--- a/python/step8_macros.py
+++ b/python/step8_macros.py
@@ -77,11 +77,14 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "quote" == a0:
return ast[1]
elif "quasiquote" == a0:
- return EVAL(quasiquote(ast[1]), env)
+ ast = quasiquote(ast[1]);
+ # Continue loop (TCO)
elif 'defmacro!' == a0:
func = EVAL(ast[2], env)
func._ismacro_ = True
diff --git a/python/step9_interop.py b/python/step9_interop.py
index 2f7c5e0..7cacf1f 100644
--- a/python/step9_interop.py
+++ b/python/step9_interop.py
@@ -77,11 +77,14 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "quote" == a0:
return ast[1]
elif "quasiquote" == a0:
- return EVAL(quasiquote(ast[1]), env)
+ ast = quasiquote(ast[1]);
+ # Continue loop (TCO)
elif 'defmacro!' == a0:
func = EVAL(ast[2], env)
func._ismacro_ = True
diff --git a/python/stepA_more.py b/python/stepA_more.py
index b9d8152..723f0ed 100644
--- a/python/stepA_more.py
+++ b/python/stepA_more.py
@@ -77,11 +77,14 @@ def EVAL(ast, env):
let_env = Env(env)
for i in range(0, len(a1), 2):
let_env.set(a1[i], EVAL(a1[i+1], let_env))
- return EVAL(a2, let_env)
+ ast = a2
+ env = let_env
+ # Continue loop (TCO)
elif "quote" == a0:
return ast[1]
elif "quasiquote" == a0:
- return EVAL(quasiquote(ast[1]), env)
+ ast = quasiquote(ast[1]);
+ # Continue loop (TCO)
elif 'defmacro!' == a0:
func = EVAL(ast[2], env)
func._ismacro_ = True