def get_fval(obj, ns): if symbol(obj): sym = obj.symbol if sym in builtins: return builtins[sym] elif sym in _Fvals: return _Fvals[sym] else: raise LispError(sym + ' is not a function/macro') elif consp(obj): return obj.eval(ns) else: raise LispError(repr(obj) + ' is not a function/macro')
def eval_user_func(obj, ns): args = list(list_iterator(obj)) if len(params) != len(args): raise LispError("nombre d'arguments incorrect") new_ns = Namespace(namespace) for (k, v) in zip(params, args): new_ns[k.symbol] = v.eval(ns) return body.eval(new_ns)
def __and(ls): if len(ls) == 2: a, b = ls return nil if nilp(a.eval(ns)) else b.eval(ns) elif len(ls) > 2: a, *_ls = ls return nil if nilp(a.eval(ns)) else __and(_ls) else: raise LispError('and must have at least 2 arguments')
def _cmp(*args): if len(args) == 2: a, b = args lisp_assert(integer(a), repr(a) + 'is not integer') lisp_assert(integer(b), repr(b) + 'is not integer') return t if op(a.nb, b.nb) else nil elif len(args) > 2: a, b, *rest = args return nil if not op(a.nb, b.nb) else _cmp(b, *rest) else: raise LispError(' must have at least 2 arguments')
def __or(ls): if len(ls) == 2: a, b = ls _a = a.eval(ns) return _a if not nilp(_a) else b.eval(ns) elif len(ls) > 2: a, *_ls = ls _a = a.eval(ns) return _a if not nilp(_a) else __or(_ls) else: raise LispError('or must have at least 2 arguments')
def rplacd(cons, o): if not consp(cons): raise LispError(repr(cons) + ' is not a cons') cons.cdr = o return cons
def _eval(obj, ns): try: return func(obj).eval(ns) except TypeError as err: raise LispError(repr(err))
def _eval(obj, ns): try: return func(*[arg.eval(ns) for arg in list_iterator(obj)]) except TypeError as err: raise LispError(repr(err))
def eval(self, namespace=_Namespace): try: return namespace[self.symbol] except KeyError: raise LispError('variable ' + self.symbol + ' has no value')
def _div(*l): try: return Integer(reduce(operator.floordiv, [e.nb for e in l])) except ZeroDivisionError as err: raise LispError('division by zero')