Harmon Nine wrote:
I think the "Powerset" function needs a correction: the H|{Powerset T}
expression won't give you what you want (unless it's a compact
expression representing the subset of the powerset that contains H).
Instead, you need to prepend H to every member of {Powerset T}, as
"PrependList" does below (using a difference list):
Wait a second. This is not what Chris Rathman asked in his first
message! Actually Chris asked for a function that chooses a set among
the powerset of L. The function proposed by Mark fits perfectly that
definition. But Chris should have called it "Subset":
fun {Subset L}
case L
of nil then nil
[] H|T then
choice H|{Subset T} [] {Subset T} end
end
end
Now your function generates the whole powerset. But I am not sure what
this procedure is supposed to do. It does not even compile, because you
put "H" as a statement:
proc {ChoiceList L}
case L
of nil then skip
[] H|T then
choice H
[] {ChoiceList T}
end
end
end
If you mean to pick an element in L, then you should write it as the
predicate Member:
proc {Member X L}
H|T=L
in
choice X=H [] {Member X T} end
end
The problem can then be written
proc {Subset X}
{Member X {Powerset [1 2 3]}}
end
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users