2

Can Some one help explain why

(define gg (lambda (ff x) (ff x x x))

has all of these properties? Thanks

gg requires two arguments when called
gg's first argument should be a function
gg's first argument should be a function that accepts 3 arguments

1 Answer 1

5
  1. gg is a lambda with two arguments, ff and x.
  2. ff is used in the expression (ff x x x) inside the lambda, so ff should be callable.
  3. The expression (ff x x x) has three arguments, so ff should be a function taking three arguments.
Sign up to request clarification or add additional context in comments.

6 Comments

i thought (ff x x x) was how the lambda is processed? In a sense, the inner function of lambda.
What do you mean by "how the lambda is processed" or "inner function"?
((lambda(ff x) (ff x x x)) 2), 2 gets passed into the lambda expression ff x then processed by ff x x x
That's an invalid expression, since the lambda expects two arguments and you're passing only one. You could, however, use ((lambda (ff x) (ff x x x)) + 2), which would be the same as calling (+ 2 2 2). In this instance, ff is + and x is 2. And + happens to be a function which can take any number of arguments, and in particular, it can take 3 arguments.
@WilliamMcCarty your new lambda expression has two function calls inside it. The result of first call is ignored the result of second call is returned. In the first call, ff receives 3 arguments; in 2nd - 4 arguments. So it must be capable to receive 3 or 4 arguments. -- The top lambda expression expect two arguments, ff and x, but you give it 5 values: +, and the 2s. This will cause an error, argument number mismatch.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.