+-+-+-+-+-+
Question:
+-+-+-+-+-+
1. For norm-unit, should the quantity in the returned QL
always be 1.0 and the uncertainty should always be 0.0?
2. What is meant by the term mutual recursion? I understand how
norm-QL would call norm-unit to get the normalized units for
those entered, but should norm-unit call norm-QL for some reason also?
+-+-+-+-+-+
Answer:
+-+-+-+-+-+
Yes - you're on the right track!
In particular:
1. Yes, norm-unit will return an uncertainty of 0.0. As for the quantity,
we imagine that we're handling 1.0 of the input unit, which might end
up as some other quantity after being normalized. (Thanks to Jane
for clarifying this!)
2. Mutual recursion just means that norm-unit will call norm-QL
and that norm-QL will call norm-unit. Nothing more than that. It'll work
because each call will be closer to one or the other base case...
Now, more generally, here's a sketch of the approach (not with Racket syntax):
norm-unit(unit):
if unit is a basic unit (assoc returns #f), then make the needed quantity list from scratch
else call norm-QL on the quantity list looked up from unicalc-db
That's completely it for norm-unit!
What about norm-QL? Here's a sketch (again with very little Racket syntax):
norm-QL(QL):
if QL has no num units nor denom units, we're done!
if QL has no num units but does have denom units,
then "peel off" one denom unit and (a) call norm-QL on what's left of QL,
(b) call norm-unit on the "peeled-off" unit, then (c) divide the results
else if QL has some num units,
then "peel off" one num unit and do steps (a), (b), and (c) as above!
What operation will you need in this case...?
The key is that each calls the other as appropriate
-- but each time, you're getting closer to the base case!