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 [(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?
select [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
- What do you call a function that returns same output as input?
- Why do function “have memory” in REBOL?
- What do you call a function that calls itself (is this called recursion)?
- extracting a function call name from a function call
- What does it mean that REST should be hypertext driven?
- Is it better call a function every time or store that value in a new variable?
- What does “error: ’myfn’ declared as function returning a function” mean?
- How can I call a lambda function from another lambda function
reprinted the original text：What should I call a REBOL function that does list comprehensions? - CodeDay