riff
riff copied to clipboard
List comprehensions
There are any number of ways to design a list comprehension syntax, so not really concerned with those details at the moment. Though I'd want it to be delimited by braces ([]
) like many other languages.
The only tricky constraint is to be able to support list comprehensions as well as vanilla "list" literals in the form [0,1,2,...]
. Python, as an example, doesn't allow the two syntaxes to coincide in the same literal. That's a reasonable restriction, though it doesn't really help wrt the compiler disambiguating a list comprehension from a vanilla literal. The biggest thing would be a syntax where the "output expression" is the first element (most common style). If the syntax had some other unique token first, it'd be a non-issue.
Ref:
- https://en.wikipedia.org/wiki/List_comprehension
- https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(list_comprehension)
- https://rosettacode.org/wiki/List_comprehensions