diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-01-11 09:34:29 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-01-11 09:34:29 -0800 |
commit | b8b1c891f17d26cf3b13e77c1657cd855ae6543b (patch) | |
tree | 9455f30feafbc711d2192bd62003a975c9b0c13b /eval.c | |
parent | 9496b3f825b80611b7bbfbc8cd9898da0412f581 (diff) | |
download | txr-b8b1c891f17d26cf3b13e77c1657cd855ae6543b.tar.gz txr-b8b1c891f17d26cf3b13e77c1657cd855ae6543b.tar.bz2 txr-b8b1c891f17d26cf3b13e77c1657cd855ae6543b.zip |
* eval.c (merge_wrap): Make generic over sequences.
* txr.1: Update documentation for merge function.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -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) |