[m-users.] Warning: this disjunct will never have any solutions.

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri May 28 06:41:37 AEST 2021


2021-05-28 06:31 GMT+10:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
> Is it safe to ignore this given I know why …my parsing code reaches a point where it knows a syntax error has been detected:
> 
> :- pred s_exp(anode::out, latok::in, latok::out) is nondet.
> s_exp(X) -->
>     (
>         (   op(_P) ->
>             expression_body(X),
>             (   cp(_)
>             ;   error_pos(P),
>                 {throw(syntax_error(P, expected_close_paren))}
>             )
>         ;
>             error_pos(P),
>             {throw(syntax_error(P, expected_open_paren))}
>         )
>     ).
> 
> I can see that throwing the exception does mean there can be no solution…I expect there is a compiler switch to silence it but I don’t like doing things like that… is there a Mercury-esque technique/approach etc that I have not yet learned about?

If op(_P) and expression_body(X) succeed, the following disjunction *will* throw
an exception after all the solutions of cp(_) have been exhausted. To me, that looks like
a genuine error to be fixed, not one to silence.

And since you are asking about Mercury-esque approaches: such an approach
would return a value that contains either the result of a successful computation
or an error description, as e.g. io.result does. It would *not* use exceptions.

Zoltan.


More information about the users mailing list