【发布时间】:2017-08-10 08:20:34
【问题描述】:
我正在学习函数式编程。当我读到关于 FP 的 lambda 部分介绍时,我想到了一个问题。
In Scheme the syntax for anonymous functions is the following one:
(lambda (arg1...argn) body)
...
We can now easily define the compose function
(define (compose f g)
(lambda (x) (f (g x))))
我很难理解x,它不在compose 函数定义的参数列表中。那么x 是如何传入的呢?
另外,假设我们有函数g1 接受参数y,z,如何调用compose? compose (f1 g1) y z?如果是这样,那么它不仅需要两个函数的参数,还需要来自 g1 的参数。我很困惑。
【问题讨论】:
-
x是结果合成的参数。假设你有函数f1和g1和参数x1,那么你可以这样称呼它((compose f1 g1) x1)。
标签: lambda functional-programming scheme