vrok / have

The Have Programming Language
http://havelang.org
BSD 2-Clause "Simplified" License
272 stars 11 forks source link

Add python-like "reverse range" #10

Open TomOnTime opened 8 years ago

TomOnTime commented 8 years ago

A major source of off-by-one errors for me has been that there is no equivalent to the Python "reverse" keyword. Forward loops are simple: for i := range s but the reverse is for i := len(s)-1; i >= 0; i--.

Please consider adding a revrange keyword or something similar.

vrok commented 8 years ago

Hi, Yep, that part of Go could get some improvement. I was thinking about something similar to Python's iterators (with __iter__ and __next__ methods), it shouldn't be that hard to do with generics (generic interfaces might be required to implement it cleanly, though, and we don't have them yet).

Reverse iteration could look like this then: for x = range reverse(s)