我应该如何称呼执行列表推导式的 REBOL 函数?
REBOL 没有内置的方法来执行列表推导。 然而,REBOL 有一个强大的工具(称为parse
),可用于创建特定于域的语言(DSL)。 我使用 parse
来创建这样一个用于列表理解的迷你 DSL。 为了解释表达式,包含推导式的块被传递给一个函数,由于缺乏更好的术语,我将其称为“comprehend”。
示例:
comprehend [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
出于某种原因,comprehend
对我来说听起来不太正确,但像 eval
这样的东西太笼统了。
我还没有发现任何其他语言需要关键字或函数来进行列表理解。 无论它们存在于何处,它们都是纯粹的语法糖。 不幸的是我没有这个选择。 那么,既然我必须有一个函数,那么它的一个好的、简洁的、合乎逻辑的名称是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
选择
怎么样?选择 [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
How about
select
?select [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
因为列表推导式可以被认为类似于映射,所以您可能会考虑将其称为“listmap”之类的名称。 或者,由于列表推导式基于集合构建器表示法,因此您可以将其称为“构建”或“构建列表”。
(免责声明:我对 REBOL 知之甚少,所以如果这些名字已经被占用,请原谅我)
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)
变形
transmogrify
do
可能是合适的,因为列表推导式只是 Monad 推导式的一个实例,而do
是 Haskell 中用于加糖 Monadic 计算的关键字,但我怀疑它对于一个人来说太模糊了。用户库。 我将列表理解函数命名为comp
,但这只是您已有函数的缩写。 也许屈服
? 例如产生[(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
。 只是眯着眼睛假装 [ ] 不存在。do
could be appropriate, as list comprehensions are just one instance of Monad comprehensions, anddo
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 functioncomp
, but that's just an abbreviation of what you already have. Perhapsyielding
? 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.