Scheme “Not a function” error

寵の児 提交于 2019-12-25 05:36:15

问题


I am learning Scheme and I keep getting this error: "Error: 20 is not a function" from the following code:

(define myFunction (lambda (x y)
(* x y)))
(define (higherOrder func x y)
(
    func x y))

(display ((higherOrder myFunction 4 5)))

I am trying to pass a function as one of the arguments. It goes through with the math since it says "20" in the error message and (5 * 4 = 20) but then it thinks it is a function. What is the problem? I cannot figure it out. I am running this code on https://repl.it/languages/Scheme.


回答1:


You have one too many pairs of parens, the expression (higherOrder myFunction 4 5) evaluates to the integer 20, then the repl tries to evaluate (20), which it can't because 20 isn't a function. When Scheme evaluates a list (where a list is anything in parens that isn't quoted) the first entry in the list is assumed to be a function.

Change the last line to

(display (higherOrder myFunction 4 5))


来源:https://stackoverflow.com/questions/35786029/scheme-not-a-function-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!