diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-03-09 07:07:59 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-03-09 07:07:59 -0800 |
commit | 7450285654ee48e010199f2e615a3451e09872f4 (patch) | |
tree | c97f186f1e334b67bd1a0385c30d73b943f04b12 /lib.c | |
parent | f33ace67e4e0760a423b460bb76ad2b99f49b2cd (diff) | |
download | txr-7450285654ee48e010199f2e615a3451e09872f4.tar.gz txr-7450285654ee48e010199f2e615a3451e09872f4.tar.bz2 txr-7450285654ee48e010199f2e615a3451e09872f4.zip |
lib: new functions join, join-with.
That old cat-str function is often a pain, requiring the
pieces as a list. We have a sys:fmt-join that is undocumented.
That functions is now exposed as usr:join, and documented.
Also introducing join-with that takes a separator as the
leftmost argument. Thus (op join-with "::") gives us
a function that joins pieces with :: in between.
* eval.c (eval_init): Regiser fmt_join function under join
symbol also. Register join-with.
* lib.c (join_with): New function.
(fmt_join): Now a wrapper for join_with that passes a nil
separator.
* lib.h (join_with): Declared.
* share/txr/stdlib/optimize.tl (basic-blocks join-blocks):
Rename the local function join, which now triggers a warning
about a standard function being redefined.
* txr.1: Redocumented cat-str, and documented join-with
and join.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -4925,15 +4925,15 @@ val scat3(val s1, val sep, val s2) return cat_str_get(&cs); } -val fmt_join(struct args *args) +val join_with(val sep, struct args *args) { - val self = lit("sys:fmt-join"); + val self = lit("join-with"); cnum index; val iter; int more; struct cat_str cs; - cat_str_init(&cs, nil, 0, self); + cat_str_init(&cs, sep, 0, self); for (index = 0, iter = args->list, more = args_more_nozap(args, index, iter); more;) @@ -4954,6 +4954,11 @@ val fmt_join(struct args *args) return cat_str_get(&cs); } +val fmt_join(struct args *args) +{ + return join_with(nil, args); +} + val split_str_keep(val str, val sep, val keep_sep) { val self = lit("split-str"); |