我应该如何称呼执行列表推导式的 REBOL 函数?

发布于 2024-07-07 11:13:57 字数 528 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

昵称有卵用 2024-07-14 11:13:57

选择怎么样?

选择 [(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])]

云胡 2024-07-14 11:13:57

因为列表推导式可以被认为类似于映射,所以您可能会考虑将其称为“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)

凉栀 2024-07-14 11:13:57

变形

transmogrify

月亮是我掰弯的 2024-07-14 11:13:57

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, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文