问题
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