diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-03-07 19:45:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-03-07 19:45:01 -0800 |
commit | fe1d0cb216b54a511ab9e3dc4f41b3ce09075997 (patch) | |
tree | 88c81759b5ba2efee3307509d4750523a5769283 /tests/012 | |
parent | b5d92c7b65b7c8efd3c62da070b52326989dfe0b (diff) | |
download | txr-fe1d0cb216b54a511ab9e3dc4f41b3ce09075997.tar.gz txr-fe1d0cb216b54a511ab9e3dc4f41b3ce09075997.tar.bz2 txr-fe1d0cb216b54a511ab9e3dc4f41b3ce09075997.zip |
New function: rangeref.
Because ranges can be iterated like sequences, and are
identified as vector-like, they have to support indexing.
However, ranges already have semantics as a function:
with a sequence argument, they slice it.
Let's put the semantics into a function called rangeref,
so it can be coherently documented.
* eval.c (eval_init): Register rangeref intrinsic.
* lib.c (generic_funcall): Range as a function works in
terms of rangeref.
(ref): Handle RNG case via rangeref.
(rangeref): New function.
* lib.h (rangeref): Declared.
* tests/012/seq.tl: New tests.
Diffstat (limited to 'tests/012')
-rw-r--r-- | tests/012/seq.tl | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/012/seq.tl b/tests/012/seq.tl index 21200268..c48296bd 100644 --- a/tests/012/seq.tl +++ b/tests/012/seq.tl @@ -825,3 +825,59 @@ (vtest [apply mapcar join (list-seq "aaa".."zzz")] (transpose (list-seq "aaa".."zzz"))) + +(mtest + (ref "a".."z" 0) :error + (ref (rcons 'foo 'bar)) :error) + +(mtest + (ref 1..6 0) 1 + (ref 1..6 1) 2 + (ref 1..6 4) 5 + (ref 1..6 5) :error + (ref 1..6 -1) 5 + (ref 1..6 -2) 4 + (ref 1..6 -5) 1 + (ref 1..6 -6) :error) + +(mtest + (ref 1..: 0) 1 + (ref 1..: 1) 2 + (ref 1..: 4) 5 + (ref 1..: -1) :error + (ref 1..: -2) :error) + +(mtest + (ref 1..t 0) 1 + (ref 1..t 1) 2 + (ref 1..t 4) 5 + (ref 1..t -1) :error + (ref 1..: -2) :error) + +(mtest + (ref #\a..#\f 0) #\a + (ref #\a..#\f 1) #\b + (ref #\a..#\f 4) #\e + (ref #\a..#\f 5) :error + (ref #\a..#\f -1) #\e + (ref #\a..#\f -2) #\d + (ref #\a..#\f -5) #\a + (ref #\a..#\f -6) :error) + +(mtest + (ref #\a..: 0) #\a + (ref #\a..: 1) #\b + (ref #\a..: 4) #\e + (ref #\a..: -1) :error + (ref #\a..: -2) :error) + +(mtest + (ref #\a..t 0) #\a + (ref #\a..t 1) #\b + (ref #\a..t 4) #\e + (ref #\a..t -1) :error + (ref #\a..: -2) :error) + + +(mtest + (ref 1..6 0.0) (1.0 2.0 3.0 4.0 5.0)) |