naming - What should I call a REBOL function that does list comprehensions? - Stack Overflow

admin2022-05-22  67

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?

Answers:

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?

Answers:

How about select?

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

Answers:

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)

Answers:

transmogrify

Answers:

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.

转载请注明原文地址:https://www.u19.cn/read-114016.html

New Post(0)