I am back working on question 2. I need to add two binary numbers. I can
assume they are both the same length.
Here is what I have written.
declare
fun {AddDigits Xs Ys C}
local Acc
case Xs of H1|T1 then
case Ys of H2|T2 then
Acc = H1 + H2 + C
end
end
if Acc == 0 then 0|{AddDigits T1 T2 0}
elseif Acc == 1 then 1|{AddDigits T1 T2 0}
elseif Acc == 2 then 0|{AddDigits T1 T2 1}
elseif Acc == 3 then 1{AddDigits T1 T2 1}
else
C|{AddDigits T1 T2 nil}
end
end
fun {Add1 X1 X2}
local Bin1 Bin2 C in
Bin1 = {Reverse X1}
Bin2 = {Reverse X2}
{AddDigits Bin1 Bin2 C}
end
end
fun {Reverse Xs}
case Xs of nil then nil
[] X|Xr then
{Append {Reverse Xr} [X]}
end
end
fun {Add Xs Ys}
{Reverse {Add1 Xs Ys}}
end
I have traced it in my head, and I thought it should work, but it keeps
telling me that I have a statement at expression position. Does anyone see
where I went wrong.
Kurt
--
Kurt Breitsprecher
(807) 474-9601
[email protected]
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users