You will find it hard to redo those predicates for scasp. Even in prolog they are very tricky. I would suggest you model the problem letting scasp do what it does best: negation and justification, and letting prolog do the rest. Otherwise you will find yourself trying to rebuild prolog within scasp. For example, to get a list of Xs that can’t fly:
:- use_module(library(scasp)).
% SCASP code
% ----------
bird(sam).
bird(tweety).
bird(john).
bird(brokenleg).
penguin(tweety).
wounded_bird(brokenleg).
% penguins and wounded birds are abnormal
ab(X) :- penguin(X).
ab(X) :- wounded_bird(X).
% birds that are not abnormal can fly
flies(X) :- bird(X), not ab(X).
%% Prolog code
%% ------------
non_flying_things(NonFlyingXs) :-
findall(X, scasp(not flies(X),[]), NonFlyingXs).
?- non_flying_things(X).
X = [_A, tweety, brokenleg],
_A ∉ [brokenleg,john,sam,tweety].
Notice prolog is the one building the list wirh findall/3. In this way you let prolog do what it does best (list manipulation) and scasp do what it does best (negation).
You can even model your problem by interleaving prolog and scasp in different steps letting each do what it does best.
EDIT: By the way, you can use scasp_assert/1
, scasp_retract/1
and scasp_retractall/1
within prolog to dynamically build up the facts for the scasp part of your program, for example you could use prolog to get a list of birds from some website using http_get/3
and then assert the facts within scasp using scasp_assert/1
. Something like this:
:- use_module(library(scasp)).
% SCASP code
% ----------
:- scasp_dynamic bird/1.
bird(sam).
bird(tweety).
bird(john).
bird(brokenleg).
penguin(tweety).
wounded_bird(brokenleg).
% penguins and wounded birds are abnormal
ab(X) :- penguin(X).
ab(X) :- wounded_bird(X).
% birds that are not abnormal can fly
flies(X) :- bird(X), not ab(X).
%% Prolog code
%% ------------
non_flying_things(NonFlyingXs) :-
scasp_assert(bird(crow)),
findall(X, scasp(not flies(X),[]), NonFlyingXs).
?- non_flying_things(X).
X = [_A, tweety, brokenleg],
_A ∉ [brokenleg,crow,john,sam,tweety].
Notice crow
was added dynamically using scasp_assert/1
, and declared with :- scasp_dynamic ...