Question

I am starting to learn Scheme and well, I am trying to implement my own max function that gives the max of just two parameters.

I've written the function like this: (define (myMax x y) (cond ((> x y) (x)) ((< x y) (y))))

But every time I try calling it (myMax 100 40)(example) I get an error that says:
The object 100 is not applicable.

Searching the documentation of GNU's MIT-Scheme, 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.
But what is that supposed to mean?

Weird thing is, I implemented a very simple function that adds two numbers and it works just fine, also an absolute value function that works fine; could it be the conditional is messed up?

Thanks

Was it helpful?

Solution

In Scheme (function-name arguments) is the syntax for applying a function to the given arguments. So (x) means "apply the function x to no arguments". However x is not a function, which the compiler is trying to tell you by saying that it's not "applicable".

Since you don't actually want to apply x, simply remove the parentheses around it. Same for (y) in the other case of the cond.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top