Courses/CS 460/Fall 2005/Homework/Gufran Mohammed/Oct 8
From CSWiki
< Courses | CS 460 | Fall 2005 | Homework | Gufran Mohammed
Late Submission
Contents |
[edit] Reverse
% Reverses the list.
local L1 L2 L3
proc {Reverse Xs ?Ys}
case Xs of H|nil then
Ys = H
[] H|T then
Ys = {Reverse T}|H
else
Ys = nil
end
end
in
L1 = [1 2 3]
{Browse {Reverse L1}}
end
[edit] Compare Lists
% Comparing if two list are equal or not.
% also works for nested lists.
local L1 L2 L3 L4
proc {Comp Xs Ys ?R}
case Xs of Hx|nil then
case Ys of Hy|nil then
if Hx == Hy then
R = true
else
R = false
end
end
[]Hx|Tx then
case Ys of Hy|Ty then
if Hx == Hy then
R = {Comp Tx Ty}
else
R = false
end
end
else
R = false
end
end
in
L1 =[ 1 2 3]
L2 =[1 2 3]
L3 =[[[1 2]4] 5]
L4 = =[[[1 2]4] 5]
{Browse {Comp L1 L2}}
{Browse {comp L3 L4}}
end

