Closed cpfr closed 8 years ago
This pull request adds the "swiss army knife of iteration"[quote by Martin Odersky] to the Monty compiler:
Iterable<Type>
Iterator<Type>
Maybe<Type>
adding for loops of the form (expresion must be of type Iterable<Type>)
expresion
for i in expression: println(i)
adding Generator functions
yield
return
generator Int Range(Int start, Int end): while start <= end: yield start start += 1 for i in Range(1,3): // [1,2,3] println(i)
start
end
[x..y]
Range(x,y)
[Int x | x in [1..5] if x % 2 = 0]
This pull request adds the "swiss army knife of iteration"[quote by Martin Odersky] to the Monty compiler:
Iterable<Type>
andIterator<Type>
classes to the core libraryMaybe<Type>
to the core libraryadding for loops of the form (
expresion
must be of typeIterable<Type>
)adding Generator functions
yield
statement instead ofreturn
start
>end
)[x..y]
, which is syntactic sugar forRange(x,y)
[Int x | x in [1..5] if x % 2 = 0]
, implemented as generators