diff options
| author | mryouse | 2022-05-21 03:29:11 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-21 03:29:11 +0000 |
| commit | 4393c6a9a138df2e50130f0310e07c1cae887534 (patch) | |
| tree | 512f76c4964bd45b144e7c1f1d485cfd843be01a | |
| parent | 50f932837a763878b58d77703b274ff242ea38f8 (diff) | |
implement branch
| -rw-r--r-- | interpreter.py | 13 |
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? |
