In order for sCASP to be useful in practice, we need to be able to process information from the network, the user, files, sensors, etc. SWI-Prolog already provides all these facilities, so here is a small proposal to allow sCASP to access the prolog functionality.
Scasp receives as input a set of terms describing a program, and it builds the possible models (list of terms) that this program can produce. My proposal is to provide the ability to produce some of the input terms by calling prolog predicates.
- My proposal is to add a { Prolog Call, Prolog Call, … } notation to sCASP.
- Each Prolog call can be:
1.1.PredicateCall(X,Y,Z)
1.2.PredicateCall(X,Y,Z) -> ScaspTerm(X,Y,Z)
Example, given the following sCASP program:
:- use_module('../../prolog/scasp/embed').
:- use_module('../../prolog/scasp/human').
% something is a moth if it does not fly during daylight.
%
:- begin_scasp(moth, [moth_scasp/1]).
moth_scasp(X) :- not flies_during_day(X).
flies_during_day(B) :- bird(B).
bird(eagle).
bird(hummingbird).
bird(bluejay).
:- end_scasp.
:- begin_scasp(prolog_embed,
We can write it embedding prolog in the following way:
% something is a moth if it does not fly during daylight.
%
:- begin_scasp(moth, [moth_scasp/1]).
moth_scasp(X) :- not flies_during_day(X).
flies_during_day(B) :- bird(B).
{ bird(X) }. % this will add to the scasp program the term bird(X)
% for all cases in which bird(X) is true.
:- end_scasp.
% this is prolog code
bird(eagle).
bird(hummingbird).
bird(bluejay).
A more useful case, suppose we ask the user if X is a bird (something that can’t be done in sCASP since it doesn’t have a way to ask a question to the user):
:- begin_scasp(moth, [moth_scasp/1]).
moth_scasp(X) :- not flies_during_day(X).
flies_during_day(B) :-
{ ask_user_if_bird(B) -> bird(B) }, % this will add to the scasp program the term bird(X)
% if ask_user_if_bird(X) is true. It could also be
% placed after the next line, order doesn't matter.
bird(X).
:- end_scasp.
% This is the prolog code, we could also get it from the network, another system, etc.
ask_user_if_bird(X) :-
format('Is ~w a bird? (y/n)?',[X]),
get_single_char(0'y).
If there is backtracking, then all the terms are added to the sCASP program (e.g. using findall/3 to get all the answers).
These are just my quick thoughts for now, but wanted to put it out there to spot problems and for comments.