Installing & calling scasp for SWI-Prolog

@Jan, following the instructions, I installed a more recent version of SWI-Prolog (threaded, 64 bits, version 8.5.9) for Windows and cloned sCASP (swipl branch). I moved to the cloned directory ?- working_directory(_,"c:/Program Files/swipl_sCASP"). and installed ?- pack_install(.). I received a lot of “passed” results (e.g. % birds.pl ...... passed 15 ms) and then some suspicious results, which may or may not be relevant:

% Warning: No  defined.
% Warning: Too old Prolog or no writeable candidate
% Warning: Could not install the scasp executable
true .

I wasn’t trying to create or install scasp as an executable. So, no worries there. But the other warnings? And finally:

?- use_module(library(scasp)).
true.

However, when I try the example from the same instructions (in the Ciao sCASP section):

p(A) :- not q(A).
q(A) :- not p(A).

The SWI-Prolog warnings box pops up for both lines, with the message format/3: Type error: textexpected, foundurl(c... I think I’m supposed to query this program with scasp(goal(p(A), [model(M), tree(T)]). but I’m not sure how to proceed. Can you offer some guidance?

Thank you
-david

I guess the installation has something to do with the make where I think the Makefile will not work for Windows.

How did you enter these? This is what I get:

?- use_module(library(scasp)).
true.

?- [user].
|: p(A) :- not q(A).
|: q(A) :- not p(A).
|: ^D% user://1 compiled 0.00 sec, 2 clauses
true.

?- ? q(X).
% s(CASP) model
{ not p(X),  q(X)
},
% s(CASP) justification
query ←
   q(X) ←
      not p(X) ←
         chs(q(X)).

Note the ?, which does the scasp solve and nicely displays the results in the toplevel. scasp/2 is more for programs that wish to reason about the result.

Thank you for that example @jan. On my Windows machine, I cannot terminate the pseudo-file [user] with CTRL-D (^D) or anything else I’ve tried. I can use assertz like so:

1 ?- use_module(library(scasp)).
true.

2 ?- assertz(p(A) :- not q(A)).
true.

3 ?- assertz(q(A) :- not p(A)).
true.

4 ?- ? q(X).
% s(CASP) model
{ not p(X),  q(X)
},
% s(CASP) justification
query ←
   q(X) ←
      not p(X) ←
         chs(q(X)).

However, I prefer to write programs in Visual Studio Code or another editor and then consult and query. When I write this in myfile.pl:

use_module(library(scasp)).
p(A) :- not q(A).
q(A) :- not p(A).

And then consult…

C:\Users\dvyd>swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.9)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- working_directory(_,"D:/Documents/Programming/Prolog/").
true.

2 ?- consult(myfile).
ERROR: d:/documents/programming/prolog/myfile.pl:2:12: Syntax error: Operator expected
ERROR: d:/documents/programming/prolog/myfile.pl:3:12: Syntax error: Operator expected
true.

Character 12 in lines 2 and 3 is the space after “not”. What am I doing wrong?

-david

:- use_module(library(scasp)).

Note the :- ! As is, you define a fact use_module/1 rather than loading the module. As the module defines not as a prefix operator the use of not q(A) becomes valid. Without it is invalid syntax.

In swipl-win.exe, ^D works. In the Windows console you can type end_of_file. Possibly ^Z works too. Running swipl.exe under Wine in Linux ^Z does Linux job control :frowning: But yes, you normally want to load programs from a file.

ah rats, :- use_module(library(scasp))., that’s a rookie mistake! Thanks @jan .

OK. It is working now. I’ll experiment a bit and then post back on my original thread regarding explaining why and why not…

Note that you can also use the system online at SWISH -- SWI-Prolog for SHaring. Great for simple experiments and you can share the links here for discussion.

1 Like