Chris,
I've been reading the CTM book, and am in Chapter 9. I haven't
actually tried programming anything in Mozart yet, but your email
inspired me to pull up the Mozart environment and give the PowerSet
function a try. Thanks for the inspiration!
Anyway, your program doesn't make a whole lot of sense to me. First,
it looks like your PowerSet function would just show subsets formed by
dropping initial elements of the list (like [0,1,2],[1,2],[2]). I'm
not experienced enough to see why your program would go into a wait
state. Second, SolveAll as presented in the book expects a function
that takes no arguments. So you have to wrap your function call.
Here's how I coded the PowerSet function using choice: For each
element of the list, I choose whether to include the element or not.
declare
fun {Maybe N}
choice
[N]
[] nil
end
end
fun {PowerSet L}
{Flatten {Map L Maybe}}
end
in
{Browse {SolveAll fun {$}{PowerSet [1 2 3]} end}}
--Mark
On 3/5/06, Chris Rathman <[EMAIL PROTECTED]> wrote:
> If I have a list of [0 1 2], I'd like to recursively generate a a choice
> that corresponds to the Power Set. That is:
>
> choice
> [0 1 2]
> [] [0 1]
> [] [0 2]
> [] [1 2]
> [] [0]
> [] [1]
> [] [2]
> [] nil
> end
>
> What I came up with was:
>
> fun {PowerSet L}
> choice
> L = nil
> [] L = _|_
> [] D L = _|D in {PowerSet D}
> end
> end
>
> local X in
> X = {SolveAll {PowerSet [0 1 2]}}
> {Show X}
> end
>
> But this goes into a wait state. So, what I'm I doing wrong? Is the
> problem in the way I'm using SolveAll, or in the PowerSet function (or
> both)?
>
> Thanks,
> Chris Rathman
>
>
>
> _________________________________________________________________________________
> mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users