### 计算中的Curried函数的实现

``````(define ((func x) y)
(if (zero? y)
((func x) 1)
12))
``````

``````(define curried (func 5))
``````

``````((func x) 1)
``````

#### 3 个答案:

``````(define (f x) 42) is short for (define f (lambda (x) 42)) .
``````

``````(define ((f x) y) (list x y)) is short for (define (f x) (lambda (y) (list x y)))
which is short for (define f (lambda (x) (lambda (y) (list x y))))
``````

（define（（f x）y）（list x y））   （f 1）

（（f 1）2）   （1 2）

（定义h（f 1））   （h 2）   （1 2）   （h 3）   （1 3）

soegaard的回答是正确的 - 这是传统的扩张。但是，drscheme很聪明！

``````(define ((substitute lv value) e)
(cond [(LogicVar? e)
(type-case LogicVar e
[lv-any (id) (if (symbol=? id (lv-any-id lv))
value
e)]
[lv-cons (f r)
(lv-cons ((substitute lv value) f)
((substitute lv value) r))])]
[(cons? e)
(cons ((substitute lv value) (car e))
((substitute lv value) (cdr e)))]
[else e]))
``````

``````(define (substitute lv value)
(local ([define inner
(lambda (e)
(cond [(LogicVar? e)
(type-case LogicVar e
[lv-any (id) (if (symbol=? id (lv-any-id lv))
value
e)]
[lv-cons (f r)
(lv-cons (inner f)
(inner r))])]
[(cons? e)
(cons (inner (car e))
(inner (cdr e)))]
[else e]))])
inner))
``````

``````(define (substitute lv value)
(local ([define inner
(lambda (e)
(cond [(LogicVar? e)
(type-case LogicVar e
[lv-any (id) (if (symbol=? id (lv-any-id lv))
value
e)]
[lv-cons (f r)
(lv-cons ((substitute lv value) f)
((substitute lv value) r))])]
[(cons? e)
(cons ((substitute lv value) (car e))
((substitute lv value) (cdr e)))]
[else e]))])
inner))
``````