Skip to content

Commit

Permalink
simplify eval
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Jul 26, 2023
1 parent b007348 commit 2ac4413
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions klongpy/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,13 @@ def eval(self, x):
* Functions (KGFn) are not invoked unless they are KGCall instances, allowing for function definitions to be differentiated from invocations.
"""

if isinstance(x, KGSym):
try:
return self._context[x]
except KeyError:
if x not in reserved_fn_symbols:
self._context[x] = x
return x
elif isinstance(x, KGCall) and not (x.is_op() or x.is_adverb_chain()):
return self._eval_fn(KGFn(x.a,x.args,x.arity))
elif isinstance(x, KGFn):
if x.is_op():
f = self._get_op_fn(x.a.a, x.a.arity)
Expand All @@ -562,6 +559,8 @@ def eval(self, x):
return f(_x) if x.a.arity == 1 else f(_x, _y)
elif x.is_adverb_chain():
return chain_adverbs(self, x.a)()
elif isinstance(x, KGCall):
return self._eval_fn(x)
elif isinstance(x, KGCond):
q = self.call(x[0])
p = not ((is_number(q) and q == 0) or is_empty(q))
Expand Down

0 comments on commit 2ac4413

Please sign in to comment.