[mercury-users] Specific If Clause Goal/Expression problem

Ralph Becket rafe at cs.mu.OZ.AU
Fri May 16 12:19:11 AEST 2003


:- func split_at_slashes(string) = list(string).

split_at_slashes(S) = string__words((pred('/'::in) is semidet), S).


	split_at_slashes("foo") = ["foo"]
	split_at_slashes("foo/bar/baz") = ["foo", "bar", "baz"]


> inter.m:094: In clause for predicate `inter:chooseInstruct/5':
> 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.

> chooseInstruct(ChoppedString, ChoppedString2, ChoppedCommaList)-->
>         (
>          if {(checkLabel(ChoppedString)= ChoppedCommaList) \= []} then

What's this supposed to do?  ------------^

> is_slash(Char):-
>         string__to_char_list("/") = [H|T],
>         H = Char.

Why make life so hard?

is_slash('/').

will do fine.

>  Can't I use the following expression, or something similar
> to this with the same effect in an if clause ? :
> 
> (checkLabel(ChoppedString)= ChoppedCommaList)\= []

No.  You can use a unification expression (look up `@' in the reference
manual) to do this sort of thing, although here it's in questionable taste.

- 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