diff options
| author | mryouse | 2022-07-21 02:57:36 +0000 |
|---|---|---|
| committer | mryouse | 2022-07-21 02:57:36 +0000 |
| commit | 076fb364c686b8a483be614b5b6f5f3250a9b0ef (patch) | |
| tree | 864f859680bcc1aa00cb99d2b1065be393d335f9 | |
| parent | bca7d0afed84bd97ccfc6dbb486746aefa9cc1f5 (diff) | |
bugfix: functools should always take a Callable
| -rw-r--r-- | neb/std/functools.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/neb/std/functools.py b/neb/std/functools.py index b0e4ad9..cfadf1c 100644 --- a/neb/std/functools.py +++ b/neb/std/functools.py @@ -1,11 +1,11 @@ -from .. import TypeEnum, Environment, Arg, Builtin, Function, evaluate, InterpretPanic, NebSyntax, MultiFunction +from .. import TypeEnum, Environment, Arg, Builtin, Function, evaluate, InterpretPanic, NebSyntax, MultiFunction, Callable from ..structs import * FUNCTOOLS = Environment() def interpretFilter(symbol, args, env, ns): func = args[0] - if not isinstance(func, MultiFunction): + if not isinstance(func, Callable): raise InterpretPanic(symbol, "requires a :func as its first argument", func) lst = args[1] out = [] @@ -24,7 +24,7 @@ FUNCTOOLS.register("filter", filter_multi) def interpretMap(symbol, args, env, ns): func = args[0] - if not (isinstance(func, MultiFunction) or isinstance(func, NebSyntax)): + if not isinstance(func, Callable): raise InterpretPanic(symbol, "requires a :func as its first argument", func) lst = args[1] if not isinstance(lst, List): @@ -43,8 +43,8 @@ FUNCTOOLS.register("map", map_multi) # TODO I think this is wrong def interpretApply(symbol, args, env, ns): func = args[0] - if not (isinstance(func, MultiFunction) or isinstance(func, NebSyntax)): - raise InterpretPanic(symbol, "requires a symbol as its first argument", func) + if not isinstance(func, Callable): + raise InterpretPanic(symbol, "requires a :func as its first argument", func) return func.call(Expr([func] + args[1].args), env, ns) apply_func = Builtin("apply", interpretApply, [Arg("func", TypeEnum.ANY), Arg("list", TypeEnum.LIST)]) @@ -54,8 +54,8 @@ FUNCTOOLS.register("apply", apply_multi) def interpretReduce(symbol, args, env, ns): func = args[0] - if not (isinstance(func, MultiFunction) or isinstance(func, NebSyntax)): - raise InterpretPanic(symbol, "requires a symbol as its first argument", func) + if not isinstance(func, Callable): + raise InterpretPanic(symbol, "requires a :func as its first argument", func) ret = args[2] # this is the accumulator for arg in args[1].args: |
