A Lazy Sequence

Comprehensions continued

In response to my post on CoffeeScript’s comprehension, Trevor Burnham — author of The CoffeeScript Bookexplained the rational behind CoffeeScript’s choices:

I think the objections here would be moot if CoffeeScript’s “list comprehensions” were called something else. They don’t behave like list comprehensions in Python, but their behavior is perfectly consistent with the CoffeeScript philosophy that every expression has a value, and loops are expressions. That means that a single loop has a single list as its value, and a loop within a loop produces a list of lists. Note that unlike Python—or Harmony—there’s no special delimiter to say “Give me a list comprehension.” It’s just the natural implication of how expressions in CoffeeScript work.
13 September 2011