by bmitc · 3y ago · 0 comments
I didn’t think otherwise. Many functional languages have comprehension syntax, and I prefer declarative programming.
> When using this pattern, it's clearer to be able to express the space with the shortest syntax rather than the verbose one.
How is
x <- [1,2,3]
or x <- {1,2,3}
more verbose than x := (1|2|3)
? Also, the first and especially second are basically identical to mathematical syntax, but the first implies order better.[(x, y) for x in [1, 3, 5] for y in [2, 7, 8] if x < y]
It's a single monolithic expression that builds the list. The choice syntax however represents each generator and each test as separate expressions, which may even be part of different functions. This seems to offer more flexibility. For example (I don't know the exact syntax):
x:=(1|2); y:=(7|8); x<y; result = (x,y)
Here result is bound to the same values as in the comprehensive list; but these values are yield one at a time, instead of being part of a structure that you traverse.