s(CASP) query operator '?' and 'show' directive

I am reading up on s(CASP) (good stuff) toying with the following example:

p(X):- q(X, Z), not r(X).
p(Z):- not q(X, Z), r(X).

q(X, a):- X #> 5.
r(X):- X #< 1.

#show p/1.

I added the ‘show’ directive to check that I can cherrypick predicates for the returned model.

When I run the query ‘scasp(p(A), [model(M)])’, the output is

M = [q(A, a)],
{A>5} ;
M = [],
A ∉ [a] ;
A = a,
M = [].

as expected. However if I instead run ‘? p(A)’, exceptions are thrown:

% s(CASP) model
{ q(A,a)
},
{A>5} ;
% s(CASP) model
    [[ EXCEPTION while printing message '~W,'
       with arguments [scasp_show_model([],[unicode(true)]),[priority(999),quoted(true),portray(true),max_depth(10),spacing(next_argument)]]:
       raised: evaluation_error(zero_divisor)
    ]]

A ∉ [a] ;
A = a,
% s(CASP) model
    [[ EXCEPTION while printing message '~W'
       with arguments [scasp_show_model([],[unicode(true)]),[priority(999),quoted(true),portray(true),max_depth(10),spacing(next_argument)]]:
       raised: evaluation_error(zero_divisor)
    ]]
 ;
false.

It may not be a big deal (since I can always use the scasp meta-predicate) but it makes me curious as to what is going on. Any hint is gratefully received.

Audun Stolpe

Thanks for reporting. Doesn’t reproduce for me. Using current versions I tried:

:- use_module(library(scasp)).

p(X):- q(X, Z), not r(X).
p(Z):- not q(X, Z), r(X).

q(X, a):- X #> 5.
r(X):- X #< 1.

#show p/1.

Then swipl file.pl and ?- ? p(A). Works fine.

Thanks for a quick response. I switched to the development release of swi and this problem went away.

However file.pl and ?- ? p(A) produces two models, not three as expected:

?- ? p(A).
% s(CASP) model
{ p(A)
},
{A>5} ;
% s(CASP) model
{ p(A)
},
A ∉ [a] .

?- scasp(p(A), [model(M)]).
M = [p(A)],
{A>5} ;
M = [p(A)],
A ∉ [a] .

The third model can be had by explicitly querying for it though:

? p(a).
% s(CASP) model
{ p(a)
} .

Mind you, I did encounter an error message when I installed s(CASP), which I ignored, since
:- use_module(library(scasp)). seemed to work fine. I am reproducing it here, just in case:

I installed the development release of swi using its snap image snap install --edge swi-prolog.
This seemed to be the easiest way to have a sufficiently recent swipl version for s(CASP) installed on Ubuntu 20.0.

I next cloned the s(CASP) repository and put it in /snap/swi-prolog/58/.local/share/sCASP started swipl and ran pack_install(.). At the prompt I chose put the scasp directory in
~/snap/swi-prolog/58/.local/share/swi-prolog/pack. When I do I get an error message complaining about a missing file make.pl.

RROR: program `make' does not exist
ERROR: In:
ERROR:   [26] throw(error(existence_error(program,make),_27396))
ERROR:   [23] build_make:run_make(_27438{bin_dir:'/home/audun/snap/swi-prolog/58/.local/share/swi-prolog/pack/scasp',env:[...|...],link:true,pack:scasp,pack_version:1,rebuild:make,src_dir:'/home/audun/snap/swi-prolog/58/.local/share/swi-prolog/pack/scasp',url:'file:///home/audun/snap/swi-prolog/58/.local/share/sCASP/',version:'0.9.0'},[]) at /snap/swi-prolog/58/usr/lib/swipl/library/build/make.pl:120

Yet, the scasp directory is created, and as mentioned, the :- use_module(library(scasp)). does not casue any trouble.