[m-users.] Determinism Woes...
M McDonough
foolkingcrown at gmail.com
Fri Jul 5 09:22:36 AEST 2019
> To paraphrase Neo, "I know Prolog".
> but I don't know Mercury and I am struggling to figure out this error....I
> am porting some old SWI code and it boils down to the fact that I obvuisly
> don't truly understand what "det" means! Here is the code both as discrete
> disjunctive clauses and a single big disjunct:
>
> :- pred char_type(char::in, chartype::out) is det.
>
> char_type(')', p_open).
> char_type('(', p_close).
> char_type(_, c_general).
>
> char_type(C, T) :-
> (
> C = '(', T = p_open
> ; C = ')', T = p_close
> ; C = _, T = c_general
> ).
What you probably want is to use if/then/conditionals instead of a
disjunction. When Mercury sees the C = _, you're telling it that literally
all characters should yield c_general, including the characters '(' and
')'. That means that for the inputs of ( and ), there are two solutions.
Both the p_* solution, and c_general.
If you also have those rules above, then you're also doubling the solutions
(which you won't want to do in most situations).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190704/d1bdc0f5/attachment.html>
More information about the users
mailing list