For Mozart-Oz Programming. Can you also explain this to me Suppose that you are
ID: 3918597 • Letter: F
Question
For Mozart-Oz Programming. Can you also explain this to me
Suppose that you are given an arithmetic expression described by a tree constructed from tuples as follows: 1. An integer is described by a tuple int(N), where N is an integer. An addition is described by a tuple add(X Y), where both X and Y are arithmetic expressions A multiplication is described by a tuple mul(X Y), where both X and Y are arithmetic expressions 1. 2. 3. Implement a function Eval that takes an arithmetic expression and returns its value. For example, add(int(1) mul(int(3) int(4)) is an arithmetic expression and its evaluation returns 13.Explanation / Answer
A tuple in oz is a special record that have integers from 1 to x, for some x>0.
The following fragment of code gives the answer:
fun {Eval X}
case X
of int(N) then N
[ ] add(X Y) then {Eval X}+{Eval Y}
[ ] mul(X Y) then {Eval X}*{Eval Y}
end
end
{Browse {Eval add(int(1) mul(int(3) int(4)))}}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.