Lisp 中照应条件句的例子是什么?

发布于 2024-09-27 05:00:47 字数 34 浏览 0 评论 0原文

Lisp 中照应条件句的例子是什么?还请解释一下代码。

What would be an example of an anaphoric conditional in Lisp? Please explain the code as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

断爱 2024-10-04 05:00:47

Paul Graham 的 On Lisp 有一章介绍 照应宏

本质上,它是一种编写语句的速记方式,可以避免重复代码。例如,compare:

(let ((result (big-long-calculation)))
  (if result
      (foo result)))

and

(if (big-long-calculation)
    (foo it))

其中 it 是一个特殊名称,指的是 (big-long-calculation) 中刚刚计算的内容。

Paul Graham's On Lisp has a chapter on Anaphoric Macros.

Essentially, it's a shorthand way of writing statements that avoids repeating code. For example, compare:

(let ((result (big-long-calculation)))
  (if result
      (foo result)))

and

(if (big-long-calculation)
    (foo it))

where it is a special name that refers to whatever was just calculated in (big-long-calculation).

故事灯 2024-10-04 05:00:47

Common Lisp LOOP 就是一个例子:

(loop for item in list
      when (general-predicate item)
      collect it)

变量 IT 具有测试表达式的值。这是 ANSI Common Lisp LOOP 工具的一个功能。

示例:

(loop for s in '("sin" "Sin" "SIN")
      when (find-symbol s)
      collect it)

返回,

 (SIN)

因为只有 "SIN" 是现有符号的名称,此处为符号 SIN。在 Common Lisp 中,符号名称默认具有内部大写名称。

An example is the Common Lisp LOOP:

(loop for item in list
      when (general-predicate item)
      collect it)

The variable IT has the value of the test expression. This is a feature of the ANSI Common Lisp LOOP facility.

Example:

(loop for s in '("sin" "Sin" "SIN")
      when (find-symbol s)
      collect it)

returns

 (SIN)

because only "SIN" is a name for an existing symbol, here the symbol SIN. In Common Lisp symbol names have internally uppercase names by default.

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