[mercury-users] Deterministic or not? (PART 2)
Sergio Rafael Trindade Marques
l16447 at alunos.uevora.pt
Tue Apr 20 08:41:41 AEST 2004
David Overton wrote:
>On Mon, Apr 19, 2004 at 07:57:21PM +0100, Sergio Rafael Trindade Marques wrote:
>
>
>>Hi,
>>I'm having a little problem with this code:
>>
>>
>>/:- pred get_ys(list(string),list(string)).
>>:- mode get_ys(in,out) is nondet.
>>
>>
>
>This should be `is det'.
>
>
>
>>get_ys(Vars,R):-
>> (Vars=[],
>> R=[]
>> ;Vars=[E|Es],
>> count_element(E,Es,0,N),
>> (N=0,
>> get_ys(Es,R)
>> ;N\=0,
>> R=[E|Rs],
>> get_ys(Es,Rs)
>> )
>> )./
>>
>>
>
>The Mercury determinism analysis algorithm is not able to infer that the
>inner disjunction will not fail, and that it can only succeed once.
>Instead you need to use an if-then-else:
>
> ( if N = 0 then
> get_ys(Es, R)
> else
> R = [E | Rs],
> get_ys(Es, Rs)
> )
>
>
>
>>/:- pred count_element(string,list(string),int,int).
>>:- mode count_element(in,in,in,out) is nondet.
>>
>>count_element(E,Elements,NI,NF):-
>> (Elements=[],
>> NF=NI
>> ;Elements=[E1|Es],
>> (E=E1,
>> N1 is NI+1,
>> count_element(E,Es,N1,NF)
>> ;E\=E1,
>> count_element(E,Es,NI,NF)
>> )
>> ).
>>
>>
>
>You will need to make the same change here.
>
>
>
>>/And it's returning the following error:
>>
>>/ In `get_pred(in, in, out)':
>>comp.m:106: error: determinism declaration not satisfied.
>>comp.m:106: Declared `det', inferred `nondet'.
>>comp.m:135: call to `get_ys(in, out)' can fail.
>>comp.m:135: call to `get_ys(in, out)' can succeed more than once.
>>
>>/I have a predicate called get_pred that it's defined as det.
>>How can i resolve the previous error and after that how can i call the
>>predicate get_ys in get_pred?
>>
>>Thanks in advance,
>>Sergio Marques
>>
>>--------------------------------------------------------------------------
>>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
>>--------------------------------------------------------------------------
>>
>>
>
>
>
Thank you very much for your help!!! It was very useful...
Sergio Marques
--------------------------------------------------------------------------
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