How do I install library(scasp)?

I’ve been playing with s(CASP) inside SWISH, but recently decided to start playing with it in a local installation of swipl on an Ubuntu virtual machine. I installed swipl-devel from source, using the instructions on the website, but if I use

:- use_module(library(scasp)).

in my code, I get

ERROR:    source_sink `library(scasp)' does not exist

I can see that GitHub - JanWielemaker/sCASP: top-down interpreter for ASP programs with constraints has a pack.pl file, and a prolog directory, but I can’t figure out from the documentation how to use the pack predicates to install it.

Any help would be appreciated.

1 Like

I went through a similar process trying to install s(CASP) as a pack to play with locally, but I figured that Jan hasn’t published it as pack yet since it didn’t appear on swi-prolog.org. I took this to be a sign that s(CASP) is still WIP in SWI-Prolog (as the README suggests).
One solution that seemed to work was cloning the sCASP repository and running swipl from within sCASP/prolog:

$ cd sCASP/prolog
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.2)
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).

?- ['scasp.pl'].
true.

EDIT:
Another option is to build a pack archive and install it locally like so:

$ cd sCASP
$ zip -r scasp-0.9.0.zip pack.pl prolog
$ swipl -q

?- pack_install('scasp-0.9.0.zip').
false.  % I don't know why I get false, 
        % but the installation works nonetheless.
        % I suspect that it's an unrelated issue as
        % I've seen it with other packs as well
?- ^D
% halt

$ cd ~
$ swipl -q

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

If you use the latest version, clone the repo, go down into the repo and run

swipl
?- pack_install(.).

Should to the job. In older versions, go to the pack directory (~/.local/share/swi-prolog/pack on POSIX systems) and symlink the sCASP directory there or clone it there.


See corrected process in this post.

1 Like

That made some progress, but it seems to fail on the tests.

?- pack_install(.).
% swipl --no-pce -O -o scasp -c prolog/scasp/main.pl
% Warning: /home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl:40:
% Warning:    '/home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl':40:48: Illegal multibyte Sequence
% Warning: /home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl:107:
% Warning:    '/home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl':111:23: Illegal multibyte Sequence
% % Disabled autoloading (loaded 111 files)
% % Disabled autoloading (loaded 8 files)
% % Disabled autoloading (loaded 0 files)
% swipl test/test_scasp.pl
% Warning: /home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl:40:
% Warning:    '/home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl':40:48: Illegal multibyte Sequence
% Warning: /home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl:107:
% Warning:    '/home/jason/src/swipl-devel/packages/sCASP/prolog/scasp/clp/disequality.pl':111:23: Illegal multibyte Sequence
% bec_light.pl ...............................
%
% Warning: /home/jason/src/swipl-devel/packages/sCASP/test/programs/bec_light.pass:1:
% Warning:    '/home/jason/src/swipl-devel/packages/sCASP/test/programs/bec_light.pass':1:5882: Illegal multibyte Sequence
ERROR: ERROR: /home/jason/src/swipl-devel/packages/sCASP/test/test_scasp.pl:40: test_scasp:main /home/jason/src/swipl-devel/packages/sCASP/test/programs/bec_light.pass:1:343: Syntax error: Operator expected
% make: *** [Makefile:10: check] Error 2
ERROR: Process "process(/usr/bin/make,[check])": exit status: 2
ERROR: In:
ERROR:   [26] throw(error(process_error(...,...),_46576))
ERROR:   [22] build_tools:build_step([test],_46626{bin_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',env:[...|...],link:true,pack:scasp,rebuild:make,src_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',url:'file:///home/jason/src/swipl-devel/packages/sCASP/',version:'0.9.0'},_46626{bin_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',env:[...|...],link:true,pack:scasp,rebuild:make,src_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',url:'file:///home/jason/src/swipl-devel/packages/sCASP/',version:'0.9.0'}) at /usr/local/lib/swipl/library/build/tools.pl:111
ERROR:   [21] apply:foldl_([[test],install],build_tools:build_step,_46626{bin_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',env:[...|...],link:true,pack:scasp,rebuild:make,src_dir:'/home/jason/.local/share/swi-prolog/pack/scasp',url:'file:///home/jason/src/swipl-devel/packages/sCASP/',version:'0.9.0'},_46742) at /usr/local/lib/swipl/library/apply.pl:316
ERROR:   [16] build_tools:build_steps([[dependencies],...|...],'/home/jason/.local/share/swi-prolog/pack/scasp','<garbage_collected>') at /usr/local/lib/swipl/library/build/tools.pl:104
ERROR:   [14] prolog_pack:pack_post_install(scasp,'/home/jason/.local/share/swi-prolog/pack/scasp',[link(true),...|...]) at /usr/local/lib/swipl/library/prolog_pack.pl:1078
ERROR:    [9] toplevel_call('<garbage_collected>') at /usr/local/lib/swipl/boot/toplevel.pl:1117
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
   Exception: (22) build_tools:build_step([test], _128{bin_dir:'/home/jason/.local/share/swi-prolog/pack/scasp', env:['PATH'='/usr/local/lib/swipl/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin', 'SWIPL'='/usr/local/lib/swipl/bin/x86_64-linux/swipl', 'SWIPLVERSION'=80502, 'SWIHOME'='/usr/local/lib/swipl', 'SWIARCH'='x86_64-linux', ... = ...|...], link:true, pack:scasp, rebuild:make, src_dir:'/home/jason/.local/share/swi-prolog/pack/scasp', url:'file:///home/jason/src/swipl-devel/packages/sCASP/', version:'0.9.0'}, _36510)

I was a bit too optimistic. The Makefile was not updated to deal with the calls it gets from pack_install/1 and there where some issues with Unicode handling that break the tests (and some more). Updated. If you pull SWI-Prolog to the latest git it will also nicely install scasp, either in the same directory of swipl or in ~/bin if one of these is writeable.

So, to install the system

git clone https://github.com/JanWielemaker/sCASP.git
cd sCASP
swipl -g "pack_install(.)" -t halt

Which should give you library(scasp), etc. to use the system from Prolog and a scasp executable in the current directory that is optionally linked from your preferred directory in $PATH.

2 Likes

Following these instructions has got me a lot closer, but still not all the way there. Here is my REPL session:

Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.3)
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).

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

?- assert(mortal(socrates)).
true.

?- scasp(mortal(X)).
X = socrates,
% s(CASP) model
{ mortal(socrates)
},
% s(CASP) justification
    [[ EXCEPTION while printing message '~W'
       with arguments [scasp_show_stack(user:'tmp-1-2599567099243887305':[[],[],o_nmr_check,[],'user:mortal'(...)],[unicode(true)]),[priority(999),quoted(true),portray(true),max_depth(10),spacing(next_argument)]]:
       raised: existence_error(procedure,'tmp-1-2599567099243887305':pr_user_predicate/1)
    ]]
.

I noticed yesterday that the embedding into the Prolog toplevel is broken after changes to how the justification is handled. I’m looking for a solution …

1 Like

Just confirming that the issue is resolved in the latest version of the sCASP package, thanks!

Two years later, I appear to have a variant of the “`library(scasp)’ does not exist” problem. I get this with the latest release of swipl (installed today). Following your instructions, I get:

Erics-MBP-4:downloads MAC$ git clone https://github.com/SWI-Prolog/sCASP.git
Cloning into 'sCASP'...
remote: Enumerating objects: 6469, done.
remote: Counting objects: 100% (336/336), done.
remote: Compressing objects: 100% (173/173), done.
remote: Total 6469 (delta 173), reused 320 (delta 160), pack-reused 6133
Receiving objects: 100% (6469/6469), 3.70 MiB | 5.69 MiB/s, done.
Resolving deltas: 100% (4199/4199), done.

Erics-MBP-4:downloads MAC$ cd sCASP
Erics-MBP-4:sCASP MAC$ swipl -g "pack_install(.)" -t halt

Create directory for packages
   (1) * /Users/MAC/.local/share/swi-prolog/pack
   (2)   /usr/local/share/swi-prolog/pack
   (3)   Cancel

Your choice? 
% swipl --no-pce --undefined=error -O -o scasp -c prolog/scasp/main.pl
% % Disabled autoloading (loaded 141 files)
% % Disabled autoloading (loaded 17 files)
% % Disabled autoloading (loaded 0 files)
% swipl -q -l prolog/scasp.pl -g check --on-warning=status -t halt
% swipl -q -l prolog/scasp/main.pl -g check --on-warning=status -t halt
% swipl test/test_scasp.pl --passed test/all_programs test/all_programs/sasp
% bec_light.pl ............................... 
% passed   598 ms
% birds.pl ................................... 
% passed    18 ms
% classic_negation_inconstistent.pl .......... 
% passed     1 ms
% family.pl .................................. 
% passed    14 ms
% forall_arity.pl ............................ 
% passed     2 ms
% hamcycle.pl ................................ 
% passed    48 ms
% hamcycle_two.pl ............................ 
% passed   126 ms
% hanoi.pl ................................... 
% passed   225 ms
% pq.pl ...................................... 
% passed     2 ms
% queens.pl .................................. 
% passed  4377 ms
% rat.pl ..................................... 
% passed     1 ms
% solve_findall.pl ........................... 
% different stacks, same models     2 ms
% vars.pl .................................... 
% passed     0 ms
% abdbirds.pl ................................ 
% different stacks, same models     8 ms
% gpa.pl ..................................... 
% passed     4 ms
% hamcycle.pl ................................ 
% passed    47 ms
% hamcycle2.pl ............................... 
% passed    43 ms
% hamcycle_two.pl ............................ 
% passed   129 ms
% hanoi_7.pl ................................. 
% passed    72 ms
% left-rec-succ_BAD.pl ....................... 
% passed     2 ms
% lion.pl .................................... 
% passed    31 ms
% loop_pos.pl ................................ 
% passed     1 ms
% loop_succ_pos.pl ........................... 
% passed     1 ms
% loopvar.pl ................................. 
% passed     2 ms
% loopvar2.pl ................................ 
% passed     2 ms
% natnum.pl .................................. 
% passed     4 ms
% path_loop.pl ............................... 
% passed    41 ms
% queens_old.pl .............................. 
% passed    56 ms
% All tests passed!
% swipl test/test_scasp.pl --passed --dcc test/all_programs/dcc
% hamilton_c.pl .............................. 
% passed   181 ms
% All tests passed!
% Installing scasp in /applications/swi-prolog.app/contents/bin/scasp
% ln -sf "/Users/MAC/Downloads/sCASP/scasp" "/applications/swi-prolog.app/contents/bin/scasp"
% ln: /applications/swi-prolog.app/contents/bin/scasp: No such file or directory
% make: *** [install] Error 1
ERROR: -g pack_install(.): Process "process(/usr/bin/make,[install])": exit status: 2
Erics-MBP-4:sCASP MAC$

The installer tries to install scasp in the same directory as SWI-Prolog, which is probably a bad idea when this is a MacOS bundle and fails. I think library(scasp) should be installed properly, no? You can link /Users/MAC/Downloads/sCASP/scasp from a place where you would like user binaries installed. Not sure what a good default location on MacOS is?