Schema parameter not applicable

I am starting to study the Scheme and well, I am trying to implement my own max function, which gives a maximum of two parameters.

I wrote the function as follows: (define (myMax xy) (cond ((> xy) (x)) ((< xy) (y))))

But every time I try to call him (myMax 100 40) (example), I get an error message:
The object 100 is not applicable.

Looking for GNU MIT-Scheme documentation, they say: This type indicates an error in which a program attempted to apply an object that is not a procedure. The object being applied is saved in the datum field, and the arguments being passed to the object are saved as a list in the operands field. This type indicates an error in which a program attempted to apply an object that is not a procedure. The object being applied is saved in the datum field, and the arguments being passed to the object are saved as a list in the operands field.
But what does this mean?

Strange, I implemented a very simple function that adds two numbers, and it works just fine, as well as an absolute value function that works fine; can it be conditional?

thanks

+4
source share
1 answer

The (function-name arguments) schema uses syntax to apply the function to the given arguments. Therefore (x) means "apply function x to any arguments." However, x not a function that the compiler is trying to tell you, saying that it is not "applicable".

Since you really don't want to use x , just remove the parentheses around it. The same for (y) otherwise cond .

+11
source

Source: https://habr.com/ru/post/1485230/


All Articles