So we had taken a test over Scheme and I got one of the problems wrong, but I have no idea how to correct it. What it asks for is:
write a Scheme function count_lambda which takes an arbitrary expression, y, and returns the number of 'lambda symbols in y. For example, invoking (count_lambda '(lambda x . lambda y . x y) z) should return 2.
The way I thought of for how to do this was to check to see if the variable was of type "lambda". However, lambda might not be a type....... Also, I pictured the expression being a list.... not sure if I can do that either...so this is what I have:
(define count_lambda
(lambda (y)
(if (null? y) 0
(cond
((lambda? y) 1)
((number? y) 0)
((cons? y) (+ (count_lambda(car y)) (count_lambda(cdr y)))))))
It says lambda is an undefined function so that right there tells me I'm looking at it wrong. Unfortunately, I have no idea what I should do for it.
Any help would be appreciated.
Thanks
x.lambdalooks like an error, perhaps you meantx . lambda? Please check and fix it. - Óscar Lópezx.lambdais not alambdasymbol, whereasx . lambdacontains alambdasymbol. It's very important that you provide correct input, even with the proper spaces in place, the sample you gave won't compile, it's an invalid expression, because of misplaced dots and parentheses - Óscar López