[mercury-users] Determinism of if-then-elses

Nicholas Nethercote njn at csse.unimelb.edu.au
Wed Apr 12 12:25:14 AEST 2006


Hi,

I have some code like this:

   :- pred get_int(int::in) : parser(literal) `with_inst` parser.

   get_int(Int, Lit, S) -->
       ( if      char('.', S)                    then get_int_dot(Lit, S)
         else if ( char('E', S) ; char('e', S) ) then get_exponent(Lit, S)
         else                                    { Lit = int(Int) }

I get a determinism error:

  zinc.m:1966: In `get_int(in, out, in, in, out)':
  zinc.m:1966:   error: determinism declaration not satisfied.
  zinc.m:1966:   Declared `semidet', inferred `nondet'.
  zinc.m:1991:   Disjunction has multiple clauses with solutions.

Fair enough -- the ref manual says an if-then-else:

   can succeed more than once if any one of the condition, the "then" part
   and the "else" part can succeed more than once.

So why does the following code from library/lexer.m compile?  The line 
marked XXX seems to be doing exactly what causes problems in my code.

   :- pred lexer__get_token(token::out, token_context::out, io::di, io::uo)
           is det.

   lexer__get_token(Token, Context, !IO) :-
         io__read_char(Result, !IO),
         (
                 Result = error(Error),
                 lexer__get_context(Context, !IO),
                 Token = io_error(Error)
         ;
                 Result = eof,
                 lexer__get_context(Context, !IO),
                 Token = eof
         ;
                 Result = ok(Char),
                 ( char__is_whitespace(Char) ->
                         lexer__get_token_2(Token, Context, !IO)
                 ; ( char__is_upper(Char) ; Char = '_' ) ->        XXX
                         lexer__get_context(Context, !IO),
                         lexer__get_variable([Char], Token, !IO)
                 ; char__is_lower(Char) ->
                         lexer__get_context(Context, !IO),
                         lexer__get_name([Char], Token, !IO)


Thanks.

Nick
--------------------------------------------------------------------------
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