diff options
-rw-r--r-- | eval.c | 5 | ||||
-rw-r--r-- | tests/012/seq.tl | 14 | ||||
-rw-r--r-- | txr.1 | 35 |
3 files changed, 49 insertions, 5 deletions
@@ -5864,7 +5864,7 @@ static val mapdov(val fun, varg lists) return map_common(lit("mapdo"), fun, lists, 0, mapdo); } -static val zip_fun(val ziparg0, varg args) +static val seq_like(val ziparg0, varg args) { seq_build_t bu; cnum index = 0; @@ -5898,7 +5898,7 @@ static val zipv(varg zipargs) func = func_n0v(vectorv); break; default: - func = func_f0v(ziparg0, zip_fun); + func = func_f0v(ziparg0, seq_like); break; } @@ -7813,6 +7813,7 @@ void eval_init(void) reg_fun(intern(lit("list-seq"), user_package), func_n1(list_seq)); reg_fun(intern(lit("vec-seq"), user_package), func_n1(vec_seq)); reg_fun(intern(lit("str-seq"), user_package), func_n1(str_seq)); + reg_fun(intern(lit("seq-like"), user_package), func_n1v(seq_like)); reg_fun(intern(lit("length"), user_package), length_f); reg_fun(intern(lit("len"), user_package), length_f); reg_fun(length_lt_s, func_n2(length_lt)); diff --git a/tests/012/seq.tl b/tests/012/seq.tl index 171ad300..97549500 100644 --- a/tests/012/seq.tl +++ b/tests/012/seq.tl @@ -1598,3 +1598,17 @@ [(wherequal 'c) '(a b c a b c)] (2 5) [(wherequal 3) '(3 3.0 b c a b c)] (0) [(wherequal 3) 0..9] (3)) + +(mtest + (make-like '(1 2 3) "") (1 2 3) + (make-like '(#\a #\b #\c) "") "abc" + (make-like '(#\a #\b 3) "") :error + (make-like '(1 2 3) #()) #(1 2 3) + (make-like '(1 2 3) #b'') #b'010203') + +(mtest + (seq-like "" 1 2 3) (1 2 3) + (seq-like "" #\a #\b #\c) "abc" + (seq-like "" #\a #\b 3) (#\a #\b 3) + (seq-like #() 1 2 3) #(1 2 3) + (seq-like #b'' 1 2 3) #b'010203') @@ -34408,24 +34408,28 @@ Additional objects that are not sequences are also iterable: numeric or character ranges, and numbers. Future revisions of the language may specify additional iterable objects. -.coNP Function @ make-like +.coNP Functions @ make-like and @ seq-like .synb .mets (make-like < list << object ) +.mets (seq-like < object << arg *) .syne .desc The +.code make-like +function's .meta list argument must be a list. If .meta object is a sequence type, then .meta list -is converted to the same type of sequence and returned. +is converted to the same type of sequence, if possible, and returned. Otherwise the original .meta list is returned. -Conversion is supported to string and vector type. +Conversion is supported to string and vector type, plus +additional types as follows. Conversion to a structure type is possible for structures. If .meta object @@ -34465,6 +34469,31 @@ available, then takes that sequence in place of .metn object , +The +.code seq-like +function creates, if possible, a sequence of the same kind as +.meta object +populated by the remaining +.meta arg +values. If some of the +.meta arg +values are not suitable elements for a sequence of that type, +then a list of those values is returned. + +The result of +.code seq-like +is consistent with what the +.code make-like +function would return if given a list of the +.meta arg +values as the +.meta list +argument. That is to say, the following equivalence holds: + +.verb + (make-like (list a0 a1 ...) o) <-> (seq-like o a0 a1 ...) +.brev + Note: the .code make-like function is a helper which supports the development of |