(a) Scoping .For each variable use site in the above code, draw an arrow from th
ID: 3590546 • Letter: #
Question
(a) Scoping.For each variable use site in the above code, draw an arrow from the use site to the binding site? Hint: There a total of 7 use sites.
(b) Evaluation.Whatdoesf(3)evaluateto?Pleaseshowtheimportantstepsofevaluation using the “e steps e in 0 or more steps” relation from the course notes: e e. For this question, we will consider function call expressions (e.g., f(3) and g(2)) and the final value important. For example, the first step is f(3) g(2). You are welcome to chain the step relation (e.g., writing e e e ··· v where the e’s are function call expressions and v is the final value).
(c) Explain briefly in one sentence what function f computes?
1. Consider the following function in Scala: def f(n: Int): Boolean = { require (n >= 0) def g(n: Int): Boolean = n match { 2 3 case 0 => false case n => f(n-1) 5 6 n match fi case 0 => true => g(n 8 1) - 10 (a) Scoping. For each variable use site in the above code, draw an arrow from the use site to the binding site? Hint: There a total of 7 use sites. (b) Evaluation. What does f (3) evaluate to? Please show the important steps of evaluation using the "e steps e' in 0 or more steps" relation from the course notes: e* e'. For this question, we will consider function call expressions (e.g., f (3) and g(2)) and the final value important. For example, the first step is f (3)* g(2). You are welcome to chain the step relation (e.g., writing e -* e'-* e"-* .. * v where the e's are function call expressions and v is the final value)Explanation / Answer
The above function f simply computes whether the number used in it's argument (parameter) is an even number or not, it returns true for f(n) if n is an even number, and false if n is odd.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.