[m-users.] Free and Ground in the same error line?

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Oct 28 21:38:09 AEDT 2023


I didn't think I had to as it was intended to be semidetached and fail if neither of the first two matched but I guess, given the syntax as documented, I need to put the final else and a  { fail } in.

I blame it on all the chemicals.......

Thanks Volker. Sigh....

> On 28 Oct 2023, at 11:36, Volker Wysk <post at volker-wysk.de> wrote:
> 
> Hi
> 
> You don't have an "else" for your second "if".
> 
> Volker
> 
> Am Samstag, dem 28.10.2023 um 11:27 +0100 schrieb Sean Charles (emacstheviking):
>> I have an error I don't quite understand, here is the code, it's a simple DCG type predicate to check that either the next token is a class name or an s-expression containing just a class name and a superclass name,
>> 
>>     380 :- pred get_class_superclass(
>>     381     ps::out, maybe(ps)::out, sr_stack::in, sr_stack::out
>>     382 ) is semidet.
>>     383
>>     384 get_class_superclass(Class, Super) -->
>>     385     ( if [ tk(Cp, Cb) ] then {
>>     386         Class = ps(Cp, Cb),
>>     387         Super = no
>>     388     }
>>     389     else if [ sexp(_, [ tk(Cp, Cb), tk(Sp, Sb) ]) ] then {
>>     390         Class = ps(Cp, Cb),
>>     391         Super = yes(ps(Sp, Sb))
>>     392     } ).
>> 
>> and the error message:
>> 
>> Making Mercury/cs/shred.c
>> shred.m:389: In clause for `get_class_superclass(out, out, in, out)':
>> shred.m:389:   mode mismatch in if-then-else.
>> shred.m:389:   The variable `Class' is ground in some branches but not others.
>> shred.m:389:     In this branch, `Class' is free.
>> shred.m:389:     In this branch, `Class' is ground.
>> shred.m:389:   The variable `Super' is ground in some branches but not others.
>> shred.m:389:     In this branch, `Super' is free.
>> shred.m:389:     In this branch, `Super' is ground.
>> ** Error making `Mercury/cs/shred.c'.
>> make: *** [felt] Error 1
>> 
>> How can a variable be both free and ground at the same time?
>> Is it the if/else-if and it being a semidet predicate?
>> 
>> Not sure!
>> Thanks,
>> Sean
>> 
>> _______________________________________________
>> users mailing list
>> users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
>> https://lists.mercurylang.org/listinfo/users
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20231028/5c52fc74/attachment.html>


More information about the users mailing list