[mercury-users] unsorted_solutions_foldl... ?

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Wed Oct 16 18:10:44 AEST 2002


Hi.

I wish to collect all outputs of a nondeterministic predicate
(solutions/2), but I need the predicate to accumulate a value during the
process. The goal is similar to unsorted_aggregate/4, but Generator and
Accumulator should be mixed together.

I need:
:- pred unsorted_solutions_foldl(pred(T, Aku, Aku), list(T), Aku, Aku).
:- mode unsorted_solutions_foldl(pred(out, di, uo) is nondet, out, di, uo)
         is cc_multi. % or better det, which is not possible by nature.

I thought about customizing unsorted_aggregate, but it's too tricky for
me.

I thought about using unsafe__unsafe_perform_io and io__set_globals,
io__get_globals this way: (I don't bother with type_to_univ conversion in
this example.)

unsorted_solutions_foldl(MyPred, Outputs, InAku, OutAku) :-
  impure unsafe_perform_io(set_globals(InAku)),
  solutions(
    (pred(Out::out) is nondet:-
      impure unsafe_perform_io(get_globals(IAku)),
      MyPred(Out, IAku, OAku),
      impure unsafe_perform_io(set_globals(OAku))
    ), Outputs),
  impure unsafe_perform_io(get_globals(OutAku)).

This approach fails on unsafe_perform_io: It's not possible to *get* any
value out of it.

Isn't there another impure unsafe solution?

Thanks, Andrew.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list