【问题标题】:scheme question code don't know why wrong方案问题代码不知道为什么出错
【发布时间】:2021-05-28 14:24:40
【问题描述】:

我要解决方案问题

我定义代码二、三、平方、加

二是f(f(x)) // 三是f(f(f(x)))

sq 是平方函数 ex ((two sq)3) 是 81

加号

(define (plus m n)
             (lambda (f) (lambda (x) (m f (n f x))

我不知道为什么错了,请告诉我

【问题讨论】:

    标签: scheme


    【解决方案1】:

    你混淆了函数的数量。 threetwo 不是两个参数的函数。它们是接受参数并返回函数的函数。返回的函数再次接受一个参数。 尝试评估以下内容:

    (let ((inc (lambda (x) (+ x 1))))
      (list ((three inc) 0)
            ((two inc) 0)))
    

    你的加分应该是:

    (define (plus m n)
      (lambda (f) (lambda (x) ((m f) ((n f) x)))))
    

    现在这应该给你(3 2 5)

    (let ((inc (lambda (x) (+ x 1))))
      (list ((three inc) 0)
        ((two inc) 0)
        (((plus two three) inc) 0)))
    

    【讨论】:

    • 谢谢各位朋友,但我的意思是二和三是 f(x)^2 ,f(x)^3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多