[mercury-users] Deterministic or not? (PART 2)

Sergio Rafael Trindade Marques l16447 at alunos.uevora.pt
Tue Apr 20 04:57:21 AEST 2004


Hi,
I'm having a little problem with this code:


/:- pred get_ys(list(string),list(string)).
:- mode get_ys(in,out) is nondet.

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)
        )
    )./

/:- 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)
        )
    ).

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



More information about the users mailing list