From f4622e734ef2be1c3793113e93219d593e3e11fb Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 7 Jul 2022 02:04:28 +0000 Subject: refactor move all functions with 'lazy' to core --- neb/std/functools.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'neb/std/functools.py') diff --git a/neb/std/functools.py b/neb/std/functools.py index 9e426b8..8a76e98 100644 --- a/neb/std/functools.py +++ b/neb/std/functools.py @@ -34,13 +34,3 @@ def interpretMap(symbol, args, env, ns): FUNCTOOLS.register("map", Builtin("map", interpretMap, [Arg("func", TypeEnum.ANY), Arg("list", TypeEnum.LIST)], return_type=Type(":list"))) -def interpretApply(symbol, args, env, ns): - # TODO: to support lambdas, we can't assume the func is defined - func = args[0] - if not isinstance(func, Symbol): - raise InterpretPanic(symbol, "requires a symbol as its first argument", func) - new_expr = Expr([func] + args[1].args) - return evaluate(new_expr, env, ns) - -FUNCTOOLS.register("apply", Builtin("apply", interpretApply, [Arg("func", TypeEnum.ANY, lazy=True), Arg("list", TypeEnum.LIST)])) - -- cgit v1.2.3 From 46cefa721d145af17bee3696ef533d752989458c Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 7 Jul 2022 03:47:22 +0000 Subject: refactor: 'apply' to functools --- neb/std/core.py | 10 ---------- neb/std/functools.py | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'neb/std/functools.py') diff --git a/neb/std/core.py b/neb/std/core.py index 1645699..f6b5b06 100644 --- a/neb/std/core.py +++ b/neb/std/core.py @@ -245,16 +245,6 @@ def interpretAnd(symbol, args, env, ns): CORE.register("and", Builtin("and", interpretAnd, [or_arg, or_arg], or_arg, Type(":bool"))) -def interpretApply(symbol, args, env, ns): - # TODO: to support lambdas, we can't assume the func is defined - func = args[0] - if not isinstance(func, Symbol): - raise InterpretPanic(symbol, "requires a symbol as its first argument", func) - new_expr = Expr([func] + args[1].args) - return evaluate(new_expr, env, ns) - -CORE.register("apply", Builtin("apply", interpretApply, [Arg("func", TypeEnum.ANY, lazy=True), Arg("list", TypeEnum.LIST)])) - def interpretBench(symbol, args, env, ns): before = datetime.now() ret = evaluate(args[0], env, ns) diff --git a/neb/std/functools.py b/neb/std/functools.py index 8a76e98..f83c49d 100644 --- a/neb/std/functools.py +++ b/neb/std/functools.py @@ -34,3 +34,11 @@ def interpretMap(symbol, args, env, ns): FUNCTOOLS.register("map", Builtin("map", interpretMap, [Arg("func", TypeEnum.ANY), Arg("list", TypeEnum.LIST)], return_type=Type(":list"))) +# TODO I think this is wrong +def interpretApply(symbol, args, env, ns): + func = args[0] + if not isinstance(func, Function): + raise InterpretPanic(symbol, "requires a symbol as its first argument", func) + return func.call(Expr([func] + args[1].args), env, ns) + +FUNCTOOLS.register("apply", Builtin("apply", interpretApply, [Arg("func", TypeEnum.ANY), Arg("list", TypeEnum.LIST)])) -- cgit v1.2.3