[mercury-users] =/2 used as a goal, not as an expression

Ralph Becket rafe at cs.mu.OZ.AU
Mon May 26 11:49:18 AEST 2003


Goncalo Jorge Coelho e Silva, Monday, 26 May 2003:
> 
> (sorry about the message flood today ;) )
> 
> Ralph wrote:
> >> inter.m:094: error: the language construct =/2 should be 
> >> inter.m:094: used as a goal, not as an expression. 
> >> inter.m:094: If you are trying to use a goal as a boolean function, 
> >> inter.m:094: you should write `if <goal> then yes else no' instead. 
> >> make: *** [run] Error 1 
> >
> >The error message seems very clear. 
> 
> Not to me I'm affraid. I tried to write the `if <goal> then yes else no'
> code suggestion but 'yes' and 'no' come up as "error: undefined predicate 
> `yes/0'"

`yes' and `no' are defined in the bool module in the library.

Looking at the code you've posted below, you're really not taking enough
care over the basic syntax.  Part of the problem is (for the 1000th
time) you are using DCGs to do IO and getting the syntax wrong.  *Don't*
use DCGs for IO, despite the fact that a lot of old code does.  Write
out the IO states longhand or use an up-to-date version of the compiler
with state variables.

> 	...
>         lookup(RegistHashIn, "mode") = ModeIn,

I'm guessing that this is a DCG predicate because (a) you are using
{...} escapes and (b) you are doing IO.  If this is the case then
you need to escape the above with {...}.  That is, if this is in a DCG
context then the above will be seen by the compiler as

	'='(lookup(RegistHashIn, "mode"), ModeIn, DCG42, DCG43)

where DCG42 and DCG43 would be the DCG variables introduced when
desugaring DCG notation.

You probably mean

	{ lookup(RegistHashIn, "mode") = ModeIn }

instead.

>         (
>         if {ModeIn = 0} then
>                 %unify(Xi,S)
>                 {io__write_string(" Update Unify - unify_value ")}

You've correctly {...} escaped the condition of the if-then-else goal.
Why have you escaped the call to io__write_string?  That surely needs
the DCG arguments if you are doing IO here.

>            else
>                 array__set(HeapIn, H, Xi, HeapOut),
>                 NewH = H + 1,
>                 set(RegistHashIn, "h", NewH) = RegistHash01

These goals *should* be escaped since they *don't* want the DCG
arguments.

>         ),
> 	...

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