[mercury-users] unsorted_solutions_foldl... ?

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Thu Oct 17 02:37:26 AEST 2002


On Wed, 16 Oct 2002, Fergus Henderson wrote:
> On 16-Oct-2002, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> > 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 think you need to step back a bit and explain what higher-level
> problem you are trying to solve, and why you think you need a
> predicate with mode `pred(out, di, uo) is nondet'.

The goal is this: I implement an interpreter of rewrite rules (to operate
on morphologically anotated sentences of natural language). The rules are
written in form of regular expression, where the 'star' or 'plus' are
applied all possible ways. Similarly, if there are more rewrite rules in
the set, they should be applied in all possible orders. The parser should
return all possible solutions.

It was quite simple to write nondeterministic predicate to return all
solutions -- and this works very well.

Now I wish to collect a log of the rewriting process, so that it would be
easy for the author of the rules to debug the rules. The log is
a directed graph with nodes to represent important states of
calculation (...and now I applied the rule 14 to the input ABC and got
the solutions X, Y and Z. Further application of rule 1,2,.. to the
solution X was not successfull...) I've already written a simple
'explorer' of this directed graph.

I know I could simply rewrite my nondet predicate, so that it would manage
to deterministically collect all the solutions and pass the log through
the stages of calculation. But I tried to do the already for three times
and never succeeded. (There are like four perpendicular options and
variable limits on the number of times a rule can be applied...) So I
wanted Mercury to do the job. :-)

> > 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.)
> A better way to implement this kind of thing would be to use the nb_reference
> type defined in extras/references.

Thanks for the reference!
It't precisely what I needed.

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