Courses/CS 460/Fall 2005/Homework/Josh Cain/Oct 22
From CSWiki
Arbor Day
local
Trees = [ash cedar maple sycamore]
Surnames = [becker clary delgado erichsen]
FirstNames = [george harvey ivan john]
% If Zs is not instantiated (or at least not bounded), then
% Xs and Ys should be. Otherwise the number of solutions will grow
% without limit.
proc {Append ?Xs ?Ys ?Zs}
choice
Xs = nil
Ys = Zs
[] Head XRest ZRest in
Xs = Head|XRest
Zs = Head|ZRest
{Append XRest Ys ZRest}
end
end
% Value is the value of field Property in the record MPs
% Both Property and Value may be uninstantiated
proc {IsAPropertyValue MPs ?Property ?Value}
{IsAMember Property#Value {Record.toListInd MPs}}
end
proc {IsATree ?Tree} {IsAMember Tree Trees} end
proc {IsASurname ?Surnames} {IsAMember Surname Surnames} end
proc {IsAFirstName ?FirstName} {IsAMember FirstName FirstName} end
proc {IsAMember ?X Xs} {Append _ X|_ Xs} end
proc {IsATail ?Xs ?Tail} {Append _ Tail Xs} end
proc {Clue1 MPs}
Surname
in
% George is not surnamed Mr. Clary or Mr. Becker
{IsAPropertyValue MPs Surname george}
{IsASurname Surname}
Surname == clary = false
Surname == becker = false
end
proc {Clue2 MPs}
FirstName
Tree
in
% Mr. Clary
{IsAPropertyValue MPs clary FirstName}
{IsAFirstName FirstName}
% planted neither the cedar tree nor the maple tree
{IsAPropertyValue MPs Tree FirstName}
{IsATree Tree}
Tree == cedar = false
Tree == maple = false
end
proc {Clue3 MPs}
Surname
in
% Harvey is not surnamed Clary
{IsAPropertyValue MPs Surname harvey}
{IsASurname Surname}
Surname == clary = false
end
proc {Clue4 MPs}
FirstName
in
% Neither John nor Ivan planted the ash tree
{IsAPropertyValue MPs ash FirstName}
{IsAFirstName FirstName}
FirstName == john = false
FirstName == ivan = false
end
proc {Clue5 MPs}
Tree Surname
in
% George did not plant the maple tree
{IsAPropertyValue MPs Tree george}
{IsATree Tree}
Tree == maple = false
% George is not surnamed Delgado
{IsAPropertyValue MPs Surname george}
{IsASurname Surname}
Surname == delgado = false
end
proc {Clue6 MPs}
Tree
in
%Mr. Erichsen did not plant the ash tree
{IsAPropertyValue MPs Tree erichsen}
Tree == ash = false
end
proc {Clue7 MPs}
Tree Surname
in
% John did not plant the maple tree
{IsAPropertyValue MPs Tree john}
{IsATree Tree}
Tree == sycamore = false
% George is not surnamed Becker
{IsAPropertyValue MPs Surname john}
{IsASurname Surname}
Surname == becker = false
end
fun {ArborDay}
Properties = {FoldR [Trees Surnames] Append nil}
MPs = {MakeRecord menProperties Properties}
in
{Clue1 MPs}
{Clue2 MPs}
{Clue3 MPs}
{Clue4 MPs}
{Clue5 MPs}
{Clue6 MPs}
{Clue7 MPs}
MPs
end
in
{Browse {SearchAll ArborDay}}
end

