summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c7
-rw-r--r--lib.c11
-rw-r--r--lib.h1
-rw-r--r--share/txr/stdlib/optimize.tl8
-rw-r--r--txr.175
5 files changed, 85 insertions, 17 deletions
diff --git a/eval.c b/eval.c
index 9591aea9..1b603ce1 100644
--- a/eval.c
+++ b/eval.c
@@ -6798,7 +6798,12 @@ void eval_init(void)
reg_fun(intern(lit("fmt-simple"), system_package), func_n5o(fmt_simple, 1));
reg_fun(intern(lit("fmt-flex"), system_package), func_n2v(fmt_flex));
- reg_fun(intern(lit("fmt-join"), system_package), func_n0v(fmt_join));
+ {
+ val join_f = func_n0v(fmt_join);
+ reg_fun(intern(lit("fmt-join"), system_package), join_f);
+ reg_fun(intern(lit("join"), user_package), join_f);
+ }
+ reg_fun(intern(lit("join-with"), user_package), func_n1v(join_with));
reg_varl(user_package_s = intern(lit("user-package"), user_package), user_package);
reg_varl(system_package_s = intern(lit("system-package"), user_package), system_package);
diff --git a/lib.c b/lib.c
index 338ff9fc..72fe13f6 100644
--- a/lib.c
+++ b/lib.c
@@ -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");
diff --git a/lib.h b/lib.h
index 3a519905..cd357004 100644
--- a/lib.h
+++ b/lib.h
@@ -873,6 +873,7 @@ val cat_str(val list, val sep);
val scat(val sep, ...);
val scat2(val s1, val s2);
val scat3(val s1, val sep, val s2);
+val join_with(val sep, struct args *args);
val fmt_join(struct args *args);
val split_str(val str, val sep);
val split_str_keep(val str, val sep, val keep_sep);
diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl
index 8719a363..babf7bce 100644
--- a/share/txr/stdlib/optimize.tl
+++ b/share/txr/stdlib/optimize.tl
@@ -431,7 +431,7 @@
(set bl.insns (butlast bl.insns)))))))
(defmeth basic-blocks join-blocks (bb)
- (labels ((join (list)
+ (labels ((joinbl (list)
(tree-case list
((bl nxbl . rest)
(cond
@@ -440,10 +440,10 @@
(null (cdr bl.links))
(null (cdr nxbl.rlinks)))
bb.(join-block bl nxbl)
- (join (cons bl rest)))
- (t (cons bl (join (cdr list))))))
+ (joinbl (cons bl rest)))
+ (t (cons bl (joinbl (cdr list))))))
(else else))))
- (set bb.list (join bb.list))))
+ (set bb.list (joinbl bb.list))))
(defmeth basic-blocks elim-dead-code (bb)
(each ((bl bb.list))
diff --git a/txr.1 b/txr.1
index 36dc62b6..ad70b0c3 100644
--- a/txr.1
+++ b/txr.1
@@ -23455,21 +23455,78 @@ function has the same parameters and semantics as the
function, except that the first argument is operated upon
using string operations.
-.coNP Function @ cat-str
+.coNP Functions @, cat-str @ join-with and @ join
.synb
-.mets (cat-str < string-list <> [ sep ])
+.mets (cat-str < item-list <> [ sep ])
+.mets (join-with < sep << item *)
+.mets (join << item *)
.syne
.desc
The
+.codn cat-str ,
+.code join-with
+and
+.code join
+functions combine items, into
+a single string, which is returned.
+
+Every
+.meta item
+argument must be a character or string object. The same is true of the
+.meta sep
+argument, if present.
+The
+.meta item-list
+argument must be a list of any mixture of characters or strings.
+
+If
+.meta item-list
+is empty, or no
+.meta item
+arguments are present, then all three functions return an
+empty string.
+
+The
.code cat-str
-function catenates a list of strings given by
-.meta string-list
-into a
-single string. The optional
+function receives the items as a single list. If the
+.meta sep
+argument is present, the items are catenated together such that
+.meta sep
+is interposed between them. If
+.meta item-list
+contains
+.I n
+items, then
+.I "n - 1"
+copies of
+.meta sep
+occur in the resulting string.
+
+If
+.meta sep
+is absent, then
+.code cat-str
+catenates the items together directly, without any separator.
+
+Copies of the items appear in the resulting string in the same
+order as the items appear in
+.metn item-list .
+
+The
+.code join-with
+function receives the items as arguments rather than a single
+.meta item-list
+arguments. The arguments are joined into a single character string
+in order, with
+.meta sep
+interposed between them.
+
+The
+.code join
+function takes no
.meta sep
-argument specifies a separator
-which is interposed between the catenated strings.
-It must be either a character or a string.
+argument. It joins all of its argument items into a single
+string, in order.
.coNP Function @ split-str
.synb