diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-04-03 20:44:41 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-04-03 20:44:41 -0700 |
commit | 5249db385aa8434d19924457a83d8bb164d9fc96 (patch) | |
tree | c0bd0075dbfb79228f46919a53dfb735e629e80b /eval.c | |
parent | 324c43c51202e914e8742e855d788312c9ebb47d (diff) | |
download | txr-5249db385aa8434d19924457a83d8bb164d9fc96.tar.gz txr-5249db385aa8434d19924457a83d8bb164d9fc96.tar.bz2 txr-5249db385aa8434d19924457a83d8bb164d9fc96.zip |
apply and iapply bugfix: split sequences into args.
These functions don't conform with the documentation. For
instance [apply list "abc"] yields "abc". It is supposed to
yield (#\a #\b #\c), since the characters of "abc" must become
individual arguments to list. Part of the fix is in the
apply_frob_args logic; however, we have to clone that function
because it is used for implementing other things which
will break: we cannot, for for example, have (list* 1 "ab")
producing (1 #\a #\b).
* eval.c (apply_intrisic_frob_args): New static function.
Differs from apply_frob_args in that it calls tolist
on the final element.
(apply_intrinsic): Use apply_intrinsic_frob_args
instead of apply_frob_args.
(iapply): Invoke tolist on the value assigned to last_arg.
* txr.1: Add a clarifying note for iapply that the terminating
atom is not split into arguments if it is a sequence.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1106,9 +1106,24 @@ static val apply_frob_args(val args) } } +static val apply_intrinsic_frob_args(val args) +{ + if (!cdr(args)) { + return tolist(car(args)); + } else { + list_collect_decl (out, ptail); + + for (; cdr(args); args = cdr(args)) + ptail = list_collect(ptail, car(args)); + + list_collect_nconc(ptail, tolist(car(args))); + return out; + } +} + val apply_intrinsic(val fun, val args) { - return apply(fun, apply_frob_args(z(args))); + return apply(fun, apply_intrinsic_frob_args(z(args))); } static val applyv(val fun, struct args *args) @@ -1129,7 +1144,7 @@ static val iapply(val fun, struct args *args) saved_ptail = ptail; if (args_more(args, index)) { - last_arg = args_get(args, &index); + last_arg = tolist(args_get(args, &index)); ptail = list_collect_nconc(ptail, last_arg); } |