1

I am a beginner in Scheme. I found this question in MIT exam 1 for SICP lecture.

What's the value and type for –

((lambda (a) (lambda (b) (+ (sqrt a) (sqrt b)))) 5)

I am having a hard time understanding how this function works. I am really confused about the parameter b. Only 5 is passed as a parameter to the outer lambda function, then what value does b take for the inner lambda function?

I tried running this function in mit-scheme but the resulting value gets incremented each time it's run.

1 Answer 1

2

You're correct that only the outer lambda form is applied to the argument 5. Then it returns its body with a replaced with 5, so it would return

(lambda (b) (+ (sqrt 5) (sqrt b)))

which is itself a function. This could later be applied to another argument, to produce an actual numeric value.

Sign up to request clarification or add additional context in comments.

2 Comments

When i run the code in mit-scheme i am getting result as follows Value 13: #[compound-procedure 13] . What is value 13 here? When i run the code again the value gets incremented as Value 14:#[compound-procedure 14]. Why does this happen?
It sounds like those might just be unique IDs generated for each procedure.

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.