summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-06-28 22:57:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-06-28 22:57:12 -0700
commitd7ea45f4c26ff460d062f24f3fbb33c018874dcf (patch)
treeb99849362e2955c4714b09d4a3774d77196317f1 /lib.c
parent1c583965749a40cdbe15846c2487f32a426dcbeb (diff)
downloadtxr-d7ea45f4c26ff460d062f24f3fbb33c018874dcf.tar.gz
txr-d7ea45f4c26ff460d062f24f3fbb33c018874dcf.tar.bz2
txr-d7ea45f4c26ff460d062f24f3fbb33c018874dcf.zip
New: callable integers and ranges.
* lib.c (do_generic_funcall): Allow integers and ranges to be function callable. They take one argument and index into it or extract a slice. In the case of ranges, this is a breaking change. Ranges can already be used in the function position in some limited ways that are not worth preserving. * tests/012/callable.tl: New file. * tests/012/iter.tl: Here we fix two instances of breakage. Using txr -C 288 will restore the behaviors previously tested here. * txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 03e6efb8..086041a0 100644
--- a/lib.c
+++ b/lib.c
@@ -8333,6 +8333,7 @@ INLINE val do_generic_funcall(val fun, struct args *args_in)
case BUF:
carray:
default:
+ dfl:
bug_unless (args->argc >= ARGS_MIN);
args_normalize_least(args, 3);
@@ -8364,6 +8365,31 @@ INLINE val do_generic_funcall(val fun, struct args *args_in)
fun = cdr(binding);
}
break;
+ case NUM:
+ case BGNUM:
+ args_normalize_least(args, 1);
+
+ switch (args->fill) {
+ case 0:
+ callerror(fun, lit("missing required arguments"));
+ case 1:
+ return ref(args->arg[0], fun);
+ default:
+ callerror(fun, lit("too many arguments"));
+ }
+ case RNG:
+ if (opt_compat && opt_compat <= 288)
+ goto dfl;
+ args_normalize_least(args, 1);
+
+ switch (args->fill) {
+ case 0:
+ callerror(fun, lit("missing required arguments"));
+ case 1:
+ return sub(args->arg[0], fun->rn.from, fun->rn.to);
+ default:
+ callerror(fun, lit("too many arguments"));
+ }
case COBJ:
if (fun->co.cls == hash_cls) {
bug_unless (args->argc >= ARGS_MIN);