[mercury-users] A subtlety about DCG variable threading

Peter Ross peter.ross at miscrit.be
Thu Apr 26 20:34:56 AEST 2001


On Thu, Apr 26, 2001 at 03:17:14AM -0700, Terrence Brannon wrote:
> It was my understanding that the only terms in a clause which would
> not receive DCG threading were those that were escaped with { }.
> 
Yes that is correct.

> Thus in run/3 below, I am confused as to why process/3 is not
> process/5 (in other words, is immune the DCG threading but not
> escaped) but io__write_string/3 is io__write_string/3 (ie, it is not
> immune to DCG threading and this is not surprising because it is not
> escaped. 
> 
> My guess is that the process/3's modes are not compatible with those
> of the head of the DCG (specifically, they are not di and uo) and that
> somehow Mercury selectively engages in the biblical act of Passover on
> them because of this, the bloody mark on the door in this case being
> incompatible modes.
> 

If there is no compatible mode for process/5, then Mercury will report a
mode error.  If only a process/3 exists, then Mercury will report an
unknown predicate error for process/5.

> 
>  > 	:- pred main(io__state::di, io__state::uo) is det.
>  > 
>  > 	:- implementation.
>  > 	:- import_module lexer, std_util, list, multi_map.
>  > 
>  > 	main -->
>  > 		run(initial_db).
>  > 
>  > 	:- mode run(in, di, uo) is det.
>  > 	run(DB0) -->
>  > 		lexer__get_token_list(Tokens),
>  > 		(if { parse(token_list_to_list(Tokens), Command) } then
>  > 			process(Command, DB0, DB),
>  > 			run(DB)
>  > 		else
>  > 			io__write_string("syntax error\n")
>  > 		).
>  > 
> 

Here is the fully expanded out code

run(DB0, IO0, IO) :-
    lexer__get_token_list(Tokens, IO0, IO1),
    ( if parse(token_list_to_list(Tokens), Command) then
        process(Command, DB0, DB, IO1, IO2),
        run(DB, IO2, IO)
    else
        io__write_string("syntax error\n", IO1, IO)
    ).

Any error message that you get will refer to this code.

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