How can I use scasp operators in the query in embed mode?

Hi,

I am figuring out the example from the document http://ceur-ws.org/Vol-2970/gdepaper1.pdf

member(X, [ X|Xs ] ).
member(X, [ _|Xs ] ):- member(X, Xs).
list( [ 1,2,3,4,5 ] ).
?- list(A), not member(B, A).

This in fact works.

In embed mode:

:- use_module( library( scasp)).

:- begin_scasp(member,[member/2,list/1]). 

member(X, [ X|Xs ] ).
member(X, [ _|Xs ] ):- member(X, Xs).
list( [ 1,2,3,4,5 ] ).

:- end_scasp.

How can I perform the same query? I am stumbling over the not operator at this point.

Regards

The begin_scasp/end_scasp does not seem to work. From previous threads, it may not be there at all, will let some one confirm.
When i tried, i get error like below:

ERROR:    catch/3: Unknown procedure: begin_scasp/2

The begin/end scasp was the first attempt to embed sCASP in Prolog. I consider it failed. Write normal Prolog code and evaluate it using sCASP semantics using scasp_call/2, ?/1, etc. That is way cleaner :slight_smile:

2 Likes

Thanks. Now it works:


:- use_module( library( scasp)).

member(X, [ X|_ ] ).
member(X, [ _|Xs ] ):- member(X, Xs).

list( [ 1,2,3,4,5 ] ).
?- ? list(A), not member(B, A).
A = [1, 2, 3, 4, 5],
% s(CASP) model
{ list([1,2,3,4,5]),          not member(B,[1,2,3,4,5]),  not member(B,[3,4,5]),      not member(B,[5]),
  not member(B,[]),           not member(B,[2,3,4,5]),    not member(B,[4,5])
},
B ∉ [1,2,3,4,5] ;
false.

Interestingly it works also when I do not define ‘member’. Scasp then seems to use the builtin member predicate. How does scasp decide how deep it has to interpret the code? Obviously I cannot call ‘writeln’ without creating an error from a scasp interpreted predicate ( “No permission to scasp procedure `system:writeln/1’”).

This can only mean that there should be a means for the call of a prolog predicate out of a scasp context.

After searching the discourse discussions about that I came up with no substantial insights.

Maybe it is also not needed. Normally a pure scasp program don’t call prolog predicates.

But to be more dynamic it should be at least possible to assert the scasp rules dynamically via assertz and then call it.

I have it, I only need to define

:- prolog writeln/1 as opaque.

Yes. That is very new and a bit experimental feature. It calls the target predicate using findall/3 and acts as if there was set of facts with the results. So, if we have not between(1,5,X), it will call findall(X, between(1,5,X), Xs) and say X ∉ [1,2,3,4,5].

Other than that, it establishes the whole call tree and verify that every predicate it finds follows the sCASP restrictions.