summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--eval.c23
-rw-r--r--txr.121
3 files changed, 35 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 0747d675..52c8a16f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-01-11 Kaz Kylheku <kaz@kylheku.com>
+
+ * eval.c (merge_wrap): Make generic over sequences.
+
+ * txr.1: Update documentation for merge function.
+
2015-01-05 Kaz Kylheku <kaz@kylheku.com>
* match.c (h_trailer): Bugfix: not returning new variable
diff --git a/eval.c b/eval.c
index 71f2470e..b02e4d0b 100644
--- a/eval.c
+++ b/eval.c
@@ -3399,12 +3399,25 @@ static val pprinl(val obj, val stream)
return ret;
}
-static val merge_wrap(val list1, val list2, val lessfun, val keyfun)
-{
- keyfun = default_arg(keyfun, identity_f);
- lessfun = default_arg(lessfun, less_f);
+static val merge_wrap(val seq1, val seq2, val lessfun, val keyfun)
+{
+ if (!nullify(seq1)) {
+ if (type(seq1) == type(seq2))
+ return seq2;
+ return make_like(tolist(seq2), seq1);
+ } else if (!nullify(seq2)) {
+ if (type(seq1) == type(seq2))
+ return seq1;
+ return make_like(tolist(seq1), seq1);
+ } else {
+ val list1 = tolist(seq1);
+ val list2 = tolist(seq2);
- return merge(list1, list2, lessfun, keyfun);
+ keyfun = default_arg(keyfun, identity_f);
+ lessfun = default_arg(lessfun, less_f);
+
+ return make_like(merge(list1, list2, lessfun, keyfun), seq1);
+ }
}
void eval_init(void)
diff --git a/txr.1 b/txr.1
index 5f886a8d..8b329d7b 100644
--- a/txr.1
+++ b/txr.1
@@ -14786,26 +14786,27 @@ value.
.SS* List Sorting
.coNP Function @ merge
.synb
-.mets (merge < list1 < list2 >> [ lessfun <> [ keyfun ]])
+.mets (merge < seq1 < seq2 >> [ lessfun <> [ keyfun ]])
.syne
.desc
The
.code merge
-function merges two sorted lists
-.meta list1
+function merges two sorted sequences
+.meta seq1
and
-.meta list2
+.meta seq2
into a single
-sorted list. The semantics and defaulting behavior of the
+sorted sequence. The semantics and defaulting behavior of the
.meta lessfun
and
.meta keyfun
-arguments are the same as those of the sort function. The input lists
-are assumed to be sorted according to these functions.
+arguments are the same as those of the sort function.
+
+The sequence which is returned is of the same kind as
+.metn seq1 .
-This function is destructive. The application should not retain references to
-the input lists, since the output list is formed out of the structure of the
-input lists.
+This function is destructive of any inputs that are lists. If the output
+is a list, it is formed out of the structure of the input lists.
.coNP Function @ multi-sort
.synb