tomo/test/ranges.tm
Bruce Hill 898bee1581 Introduce a Match struct to represent pattern matching results, which
improves the usability of a lot of the APIs. Also bugfix some issues
with ranges.
2024-11-09 16:27:54 -05:00

32 lines
509 B
Tcl

func main():
>> r := 5:to(10):by(2)
= Range(first=5, last=10, step=2)
>> r.first
= 5
>> r.last
= 10
>> r.step
= 2
>> Range(1, 5) == 1:to(5)
= yes
>> 1:to(5) == 5:to(1):reversed()
= yes
>> Range(1, 5) == Range(5, 10)
= no
>> [i for i in 3:to(5)]
= [3, 4, 5]
>> [i for i in 3:to(10):by(2)]
= [3, 5, 7, 9]
>> [i for i in 3:to(10):reversed():by(2)]
= [10, 8, 6, 4]
>> [i for i in (2:to(10):by(2)):by(2)]
= [2, 6, 10]