Extending the for loop to have multiple clauses


(Al Skipp) #1

I like this idea, but would certainly prefer it to be an expression (your alternative suggestion, array comprehension) rather than a statement. Your example of building an array of tuples [(suit, rank)] could then be achieved without having to append to a var during iteration.

···

Yes, it’d be great if you can combine it with where. Alternatively, it could be interesting to instead explore array comprehension syntax, rather than making `for` smarter. That’d allow for a more functional style. For example, Norvig’s spelling corrector (http://norvig.com/spell-correct.html) would then be very straightforward to port.

Re the x operator: it’s even easier if you define it with flatMap. However, the for syntax is different, because the second clause can depend on the first...

Chris