What should I call a REBOL function that does list comprehensions?
Asked Answered
G

4

6

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?

Gynandromorph answered 15/10, 2008 at 8:33 Comment(1)
Here's the source code for the list comprehension: blog.revolucent.net/2009/04/dirt-simple-dsl-in-rebol.htmlShala
H
4

How about select?

select [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]

Halibut answered 1/2, 2009 at 21:44 Comment(1)
Rebol already has a select function, and it's important. Not this name.Lauraine
D
2

Because list comprehensions can be thought of as analogous to map, you might think about calling it something like "listmap". Alternately, because list comprehensions are based on set-builder notation, you could call it something along the lines of "build" or "buildlist".

(Disclaimer: I know very little about REBOL, so forgive me if these names are already taken)

Dorothadorothea answered 1/2, 2009 at 21:25 Comment(0)
D
2

transmogrify

Dinodinoflagellate answered 2/2, 2009 at 1:29 Comment(0)
D
1

do could be appropriate, as list comprehensions are just one instance of Monad comprehensions, and do is the keyword used in Haskell for sugared Monadic computations but I suspect it's too vague for a user library. I called my list comprehension function comp, but that's just an abbreviation of what you already have. Perhaps yielding? E.g. yielding [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]. Just sort of squint and pretend the [ ] aren't there.

Diagraph answered 1/2, 2009 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.