[mercury-users] some_of_solutions/2
Mark Brown
dougl at cs.mu.OZ.AU
Thu Apr 4 15:25:09 AEST 2002
I agree with Ralph about destroying the declarative semantics. I have
some further remarks to add:
On 04-Apr-2002, Dave Slutzkin <dave_slutzkin at yahoo.com> wrote:
> I began to try writing a predicate 'fullsublist' which would have both modes
> (in,out) and (in,in) - it would check to ensure that a list was _any_ sub
> list in the in,in mode, and would produce a full sublist in the in,out mode.
> But this proved tricky.
Indeed it would have, because what you are describing here is not one but
two different predicates. A solution in the (in, in) mode which did not
include the full sublist would not be a solution in the (in, out) mode,
but a predicate can only have one solution set --- the set of solutions
cannot depend on the mode.
> If I could check a variable's bound/unbound status at run-time I could make
> all these problems go away. But I can't find any mention of this in the
> docs. Can anyone see a simple solution to this relatively simple problem?
There is no way to directly check a variable's bound/unbound status at
run-time. In fact, in most grades there is no special representation
for unbound variables --- they contain garbage. There is no way to tell
just by looking at it whether a piece of data is in fact just random
garbage.
One technique you can use to get around this is to pass an extra argument
which specifies which "mode" the predicate is operating in. In your
example, you could define
:- type solution_set ---> all_solutions ; some_solutions.
and pass a value of this type as the first argument. You may still need
different clauses for different modes, but something like the desired
result could be achieved without destroying the declarative semantics.
Hope this helps,
Mark.
--------------------------------------------------------------------------
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