diff options
| author | mryouse | 2022-05-12 02:56:14 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-12 02:56:14 +0000 |
| commit | acaf5dc93d2495b709e0d059b9037ceb143de3af (patch) | |
| tree | 3b3e9d75dd5841400137222336256b03339aae34 | |
| parent | 6e83ec4e8c5315712744d98b5e89d85c45ecef40 (diff) | |
if with no else
| -rw-r--r-- | std.py | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -59,18 +59,18 @@ def std_concat(arg1, arg2): return NebString(f"{arg1.value}{arg2.value}") # flow control -def std_if(cond, t_branch, f_branch): +def std_if(cond, t_branch, f_branch=None): if cond.value: if isinstance(t_branch, NebExpression): - ret = evaluate_expression(t_branch) + return evaluate_expression(t_branch) else: - ret = t_branch - else: + return t_branch + elif f_branch is not None: if isinstance(t_branch, NebExpression): - ret = evaluate_expression(f_branch) + return evaluate_expression(f_branch) else: - ret = f_branch - return ret + return f_branch + return NebBool(True) # type validation def std_is_string(arg): @@ -159,8 +159,9 @@ def build_std(): STD["concat"] = [concat_string_string] # flow control - if_bool_expr_expr = FuncImpl(NebFunction("if", [NebBool, NebAny, NebAny], NebAny), std_if) - STD["if"] = [if_bool_expr_expr] + if_bool_any_any = FuncImpl(NebFunction("if", [NebBool, NebAny, NebAny], NebAny), std_if) + if_bool_any = FuncImpl(NebFunction("if", [NebBool, NebAny], NebAny), std_if) + STD["if"] = [if_bool_any_any, if_bool_any] # type checking is_string = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_string) |
