aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2022-05-21 03:29:11 +0000
committermryouse2022-05-21 03:29:11 +0000
commit4393c6a9a138df2e50130f0310e07c1cae887534 (patch)
tree512f76c4964bd45b144e7c1f1d485cfd843be01a
parent50f932837a763878b58d77703b274ff242ea38f8 (diff)
implement branch
-rw-r--r--interpreter.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/interpreter.py b/interpreter.py
index ee7069c..4677432 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -291,6 +291,19 @@ def interpretPipe(expr, env):
GLOBALS.register("|", Builtin(interpretPipe))
+def interpretBranch(expr, env):
+ if len(expr.args) == 0:
+ raise Exception("'branch' takes at least one expression")
+ for arg in expr.args:
+ if len(arg.args) != 1:
+ raise Exception("'branch' branches have two expressions")
+ cond = evaluate(arg.symbol, env) # this is the condition
+ if cond:
+ return evaluate(arg.args[0], env)
+ return None
+
+GLOBALS.register("branch", Builtin(interpretBranch))
+
def interpretEnv(expr, env_expr, env):
ev = evaluate(env_expr, env)
return ev # TODO more than this?