Bug in cplint

I’m using: SWI-Prolog version 8.4.1

:- use_module( library( pita)).

:- pita.

:- begin_lpad.


? :: findme.

a :- findme.
b :- findme.

utility( a , 10).
utility( b , -5). % correct outcome

top :- a , b.

:- end_lpad.

/*
(ins)?- dt_solve(A, B).
A = [[findme]],
B = 5.0.
*/

:- use_module( library( pita)).

:- pita.

:- begin_lpad.


? :: findme.

a :- findme.
b :- findme.

utility( a , 10).
utility( b , - 5). % incorrect outcome

top :- a , b.

:- end_lpad.

/*
(ins)?- dt_solve(A, B).
A = [[findme]],
B = 10.0. % wrong
*/

If in the utility directive a negative value is written then a space between ‘-’ and the value lets the effect of this directive disappear. I don’t believe this is intended.

Regards.

Not entirely following the ISO standard, SWI-Prolog reads - 5 as -(5). Only if there is no space it is read as a negative number.

In don’t know what happens under the bonnet when I replace -5 by - 5. It is as if the rule disappears.

(ins)?- A is -5, B is - 5.
A = B, B = -5.

Even if -5 and -(5) are different terms the package should either thow an error or interpret it correctly.

$ grep '\<utility\>' pita.pl 
% :- dynamic utility/2.
  F = utility,
% tab dir for utility variables
  F = utility,!,
% utility attributes with body
% utility(a,N):- b.
  (Head = (H => U) ; Head = utility(H,U)), ground(H), number(U), !,
% utility attributes without body
% utility(a,N).
  (Head = (H => U) ; Head = utility(H,U)), ground(H), number(U), !.

I believe this is the part.

number should be replaced by must_be or something likt that.

Regards.

Thanks for the suggestion.
We have updated the cplint code (see github Better error handling in utility/2 · friguzzi/cplint@b4497e8 (github.com)) to handle your scenario.
Now, if you use this program

? :: findme.
a :- findme.
b :- findme.
utility( a , 10).
utility( b , - 5). 
top :- a , b.

You get

swipl -s test_dt.pl
ERROR: Prolog initialisation failed:
ERROR: Unknown message: error(“Expected a number for utility in utility/2”)

Let me know if you have further questions or suggestions.
Best regards.

2 Likes

Thank you very much.