mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Range operators!
Added ".." and "..." infix operators. Num implements them to
return Range objects. Those in turn implement the iterator
protocol, so now numeric for loops are easy:
for (i in 1..10) { ... }
I also cleaned up the Wren benchmarks to use this.
In the process, I discovered the method_call benchmark really
just showed loop peformance, so I unrolled the loops in all of
the languages to stress method calls.
This commit is contained in:
14
test/number/range.wren
Normal file
14
test/number/range.wren
Normal file
@ -0,0 +1,14 @@
|
||||
var inclusive = 2..5
|
||||
IO.write(inclusive is Range) // expect: true
|
||||
IO.write(inclusive.min) // expect: 2
|
||||
IO.write(inclusive.max) // expect: 5
|
||||
|
||||
var exclusive = 2...5
|
||||
IO.write(exclusive is Range) // expect: true
|
||||
IO.write(exclusive.min) // expect: 2
|
||||
IO.write(exclusive.max) // expect: 4
|
||||
|
||||
// TODO: Non-number RHS.
|
||||
// TODO: Non-integer RHS.
|
||||
// TODO: Range iteration.
|
||||
// TODO: Empty or negative ranges.
|
||||
Reference in New Issue
Block a user