lambda - 这个方案代码是什么意思? (使用 lambda 定义 'list' 运算符)

标签 lambda scheme racket

作为编译并返回参数列表的列表运算符的定义,我在 this tutorial 找到了此方案代码。

(define list
(lambda args args))

但是,这与我所知道的通常的 lambda 语法不匹配。我的意思是,lambda 应该将参数放在括号等中。请解释它是如何工作的。

最佳答案

虽然 lambda 中参数的一般形式似乎总是包含括号,但这并不是必需的。如果看一下this sectionThe Scheme Programming Language 4e ,它说:

The general form of lambda is a bit more complicated than the form we saw earlier, in that the formal parameter specification, (var ...), need not be a proper list, or indeed even a list at all. The formal parameter specification can be in any of the following three forms:

  1. a proper list of variables, (var1 ... varn), such as we have already seen,
  2. a single variable, varn, or
  3. an improper list of variables, (var1 ... varn . varr).

In the first case, exactly n actual parameters must be supplied, and each variable is bound to the corresponding actual parameter. In the second, any number of actual parameters is valid; all of the actual parameters are put into a single list and the single variable is bound to this list.

粗体部分(粗体是我设置的),是与你的问题非常相关的部分。正如您的教程所说,它是一个转换为列表的可变参数参数。

关于lambda - 这个方案代码是什么意思? (使用 lambda 定义 'list' 运算符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32577660/

相关文章:

c# - 具有聚合函数的 lambda 表达式

java - 如何对 Double 而不是 Integer 进行 Java lambda 求和?

c# - 连接两个 List<T>,其中每个列表中的字段值相等

scheme - PLT 方案菜鸟 : Boolean and/or aren't procedures?

Racket : I'm trying to build a function returning all values associated with key

时间:2019-05-10 标签:c++lambda: Currying sum function: returns different results using capture by value vs by reference

macros - 在 Scheme 中捕获宏

windows - 在 Windows 命令行上运行 raco

racket - 垂直条可以用作 Racket 中标识符的一部分吗?

emacs - 如何使用Emacs运行方案?