aboutsummaryrefslogtreecommitdiff
path: root/neb
diff options
context:
space:
mode:
Diffstat (limited to 'neb')
-rw-r--r--neb/__init__.py9
-rw-r--r--neb/exceptions.py5
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)