# Installing & calling scasp for SWI-Prolog

**URL:** <https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221>\
**Category:** Pack\
**Created:** [April 4, 2022, 3:47pm UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221 "2022-04-04T15:47:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![d-vyd](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/d-vyd/32/4191_2.png) [@d-vyd](https://swi-prolog.discourse.group/u/d-vyd)\
**Post date:** [April 4, 2022, 3:47pm UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/1 "2022-04-04T15:47:02Z")

</div>

@Jan, following the [instructions](https://github.com/JanWielemaker/sCASP), I installed a more recent version of SWI-Prolog (threaded, 64 bits, version 8.5.9) for Windows and cloned [sCASP](https://github.com/JanWielemaker/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:

```prolog
% 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:

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

```

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

```prolog
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: `text`expected, found`url(`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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 4, 2022, 4:23pm UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/2 "2022-04-04T16:23:27Z")

</div>

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

> [@d-vyd](#):
>
> warnings box pops up for both lines

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

```prolog
?- 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.

---

<div class="post-metadata">

**Author:** ![d-vyd](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/d-vyd/32/4191_2.png) [@d-vyd](https://swi-prolog.discourse.group/u/d-vyd)\
**Post date:** [April 5, 2022, 5:52am UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/3 "2022-04-05T05:52:29Z")

</div>

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:

```prolog
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:

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

```

And then consult…

```prolog
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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 5, 2022, 6:52am UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/4 "2022-04-05T06:52:31Z")

</div>

> [@d-vyd](#):
>
> `use_module(library(scasp)).`

```
:- 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.

> [@d-vyd](#):
>
> Windows machine, I cannot terminate the pseudo-file `[user]` with CTRL-D ( `^D` ) or anything else I’ve tried.

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 ☹ But yes, you normally want to load programs from a file.

---

<div class="post-metadata">

**Author:** ![d-vyd](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/d-vyd/32/4191_2.png) [@d-vyd](https://swi-prolog.discourse.group/u/d-vyd)\
**Post date:** [April 5, 2022, 7:37am UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/5 "2022-04-05T07:37:11Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 5, 2022, 8:48am UTC](https://swi-prolog.discourse.group/t/installing-calling-scasp-for-swi-prolog/5221/6 "2022-04-05T08:48:34Z")

</div>

Note that you can also use the system online at [SWISH -- SWI-Prolog for SHaring](https://swish.swi-prolog.org/example/scasp.swinb). Great for simple experiments and you can share the links here for discussion.
