8 Consider the Scheme function below define fun lambda arg c
8. Consider the Scheme function below (define fun (lambda (arg) (cond ((null? arg) (Clist? arg car arg)) ((number? arg) (+ arg 1)) (else 0) arg) Which of the following function evaluations are correct? (mark one or more, 4 points) (a) (fun 5) evaluates to 6 (b) (fun \"3\") evaluates to \"4\" (c) (fun \'(a b)) evaluates to a (d) (fun (fun \'())) evaluates to 1
Solution
a). here 5 is a number .so according to the schema if the arg is a number it is incremented by 1
so 5 is incremented by 1 which equals to 6
b)b is gals...It displays \"3\".....it comes under else part in our schema
c)it comes under. List of arguments ..we have a and b...so a is evaluated
d)first fun() evaluates to 0...it is a recursionso 0 is passed as number argument to fun again ..so it evaluates to 1.
