REBOL has no built-in way to perform list comprehensions. However, REBOL has a powerful facility (known as parse
) that can be used to create domain-specific languages (DSLs). I've used parse
to create such a mini-DSL for list comprehensions. In order to interpret the expression, the block containing the comprehension is passed to a function, which for lack of a better term I've called comprehend
.
Example:
comprehend [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
For some reason, comprehend
doesn't sound right to me, but something like eval
is too general.
I haven't found any other language that requires a keyword or function for list comprehensions. They are pure syntactic sugar wherever they exist. Unfortunately I don't have that option. So, seeing that I must have a function, what's a good, succinct, logical name for it?