diff options
| author | mryouse | 2022-07-14 02:19:33 +0000 |
|---|---|---|
| committer | mryouse | 2022-07-14 02:19:33 +0000 |
| commit | 2154c4fd811c5669c217593250476dda860aac36 (patch) | |
| tree | 763d9fcda6a8a9ce23c45b2ffa4e28f688376b57 | |
| parent | 00c5c7e2c043949ee8b3d6c32b01d338102da51f (diff) | |
bugfix: let things that aren't symbols be called
| -rw-r--r-- | neb/__init__.py | 9 | ||||
| -rw-r--r-- | neb/exceptions.py | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/neb/__init__.py b/neb/__init__.py index e3167b9..e93f0dd 100644 --- a/neb/__init__.py +++ b/neb/__init__.py @@ -41,7 +41,14 @@ def evaluate(expr, env, ns=None): elif len(expr.args) == 0: return expr - if not isinstance(expr.args[0], Symbol): + elif isinstance(expr.args[0], Expr): + ev = evaluate(expr.args[0], env, ns) + return evaluate(Expr([ev] + expr.args[1:]), env, ns) + + elif isinstance(expr.args[0], Callable): + return expr.args[0].call(expr, env, ns) + + elif not isinstance(expr.args[0], Symbol): raise NebPanic("can't evaluate without a symbol") name = expr.args[0].name if env.contains(name): diff --git a/neb/exceptions.py b/neb/exceptions.py index cc0f915..c34097a 100644 --- a/neb/exceptions.py +++ b/neb/exceptions.py @@ -3,7 +3,10 @@ class NebPanic(BaseException): class InterpretPanic(NebPanic): def __init__(self, sym, msg, arg=None): - big_message = f"[{sym.line}] '{sym.name}': {msg}" + if hasattr(sym, "line"): + big_message = f"[{sym.line}] '{sym.name}': {msg}" + else: + big_message = f"[??] '{sym.name}': {msg}" if arg is not None: big_message += f" (got {arg})" super().__init__(big_message) |
