[not loaded]All predicatesShow sourcesscasp.pl -- s(CASP) from Prolog

Load this, write the program as ordinary Prolog clauses, and ask:

:- use_module(library(sscasp)).

bird(tweety).
bird(polly).
penguin(polly).
flies(X) :- bird(X), not penguin(X).

?- ? flies(X).
Model:
    bird(tweety)
    flies(tweety)
    not penguin(tweety)
X = tweety.

scasp/2 is the predicate; the ?-prefixed operators are the same thing with the printing chosen for you, for use at a toplevel. scasp/2 collects the clauses the query reaches — see sscasp/dyncall.pl for what that means and for how a program says the things Prolog has no syntax for.

The shortcuts

Each asks for what its name says — the + and - are the model and the justification, in that order — and the toplevel shows it, as part of the answer:

`?-- Q`bindings only
`?+- Q`, `? Q`and the model
`?-+ Q`and the justification
`?++ Q`, `?? Q`both
`??+- Q`, `??-+ Q`, `??++ Q`the same, said in words

They are ordinary nondeterministic goals: ; at the toplevel asks for the next answer, and shows it the same way.

They show nothing outside a toplevel. The model reaches the terminal through residual_goals//0, which is the toplevel's hook for adding to an answer, and that is deliberate: the model then comes after the bindings, and the toplevel names the variables of the answer and of the model together — `¬ ab(_A) and _A` being anything but john or sam are one variable, and a model printed on its own could not say so. To print from a program, use scasp_human/1,2, or scasp/2 with portray_model/2 and portray_justification/2.

Source user:term_expansion(+Term, -Expanded) is semidet[multifile]
A global constraint is a rule with no head. :- Body. in a Prolog file is a directive to run at load time, and false/0 is a built-in that cannot be given clauses, so false :- Body. becomes a clause of 'scasp$constraint'/1 in the same module instead — see sscasp/dyncall.pl:constraint_clauses/2.

In user because that is where SWI looks: an expansion exported from a library is not consulted for the module that imported it. The old implementation puts its own there for the same reason (scasp/dyncall.pl, which maps false :- Body onto a clause of -/0).

Source claimed(?Term, ?Module, -Expanded) is nondet[private]
The spellings both libraries read, and what this one expands each to in Module: a directive recording it, or for a global constraint the clauses holding it. Everything else about the spellings is the same, which is why they are a table rather than separate expansions.
`:- pred Spec`a signature here, a description in the old tree, whose expansion raises on this spelling rather than declining it
`:- scasp_dynamic Spec`declares p/N and -/1; the old tree declares the interned '-p'/N, which this one never puts a clause in
`#pred Spec`the spelling s(CASP) programs are written in — 84 in `test/le_programs/` alone
`#abducible Spec`, `:- abducible Spec`an abducible; the old tree calls its own abducible/1
`#show Spec`, `:- show Spec`what the model shows
`#sld Spec`, `#domain Spec`, `#describe Spec`the file spelling of :- sld, :- domain, :- describe, so a program reads the same in a module and in a file
false :- Bodya global constraint; the old tree makes it a clause of -/0

Qualified with sscasp_dyncall because what the guard establishes is that the file imported scasp/2, not that it imported these: use_module(library(sscasp), [scasp/2]) is a file we claim and in which a bare pred/1 would not resolve.

Source template(@Spec, ?Module, -Goal) is det[private]
`#pred p(X) :: 'text'` is a description and `#pred p(dom)` a signature. The description goes to describe/1 rather than pred/1, so it does not warn: source.pl:partition_terms/7 makes the same choice, because the warning is for `:- pred X :: "..."` written where :- describe was available and `#pred` is what the generator emits.
Source ours(+Module) is semidet[private]
Module is being compiled against this library rather than the old one. Anything installed in user is consulted for every file in the process, so it has to ask which library the file it is firing on imported — prolog_load_context(module, M) for the file, and then this. scasp/dyncall.pl:ours/0 asks the mirror-image question, so the two never both fire and load order decides nothing.

scasp/2 is the marker rather than the directive being claimed, because it is what a file imports the library for: a file that has pred/1 has it by way of scasp/2, and a file that has neither is not speaking to either library. The property survives the re-export through library(sscasp), which is why it can be asked of the importing module rather than of the library.

Source negated_clause(@Term) is semidet[private]
Term is a clause of -/1: a classically negated fact or rule.
Source local_negation(@Head, @Body, -Literal, -Local) is nondet[private]
Literal is a `not G` in Body's conjunction, G a user literal, and Local the variables of G that occur nowhere else in the clause, named as the reader named them, _ for an anonymous one.
Source scasp_residuals// is det[private]
Add the model and the justification to the toplevel's answer. They are emitted as goals the toplevel then portrays, which is how the old implementation does it (scasp/embed.pl) and why the variables come out named: the toplevel names the whole answer — bindings, model and the constraints still on the answer's variables — in one go, so a variable two of them share is one name.

Nothing is emitted unless the query asked, which is what separates `? Q from scasp(Q)`.

Source scasp_human(:Query) is nondet
Source scasp_human(:Query, +Options) is nondet
The same, said in words: each literal by its :- describe template where the program wrote one, and by sscasp/lang.pl's vocabulary where it did not. This is the old implementation's `--human`, and it goes through the same HTML description — see sscasp/html.pl.

Unlike the ?-shortcuts this prints, so it is the one to use from a program. Options are scasp/2's, plus show_model(Boolean) and show_justification(Boolean), both true here.

Source solve_and_show(:Query, +Options) is nondet[private]
The model and the justification are made readable together, and with the query: a variable shared between them has to get one name, or the three printed terms say different things by the same letter.
Arguments:
Options- are scasp_human/2's, plus human(Boolean) to say the answer in words.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 scasp(Arg1)
 scasp(Arg1, Arg2)
 scasp_query_clauses(Arg1, Arg2)
 scasp_query_clauses(Arg1, Arg2, Arg3)
 scasp_directive(Arg1)
 scasp_show(Arg1, Arg2)
 scasp_json(Arg1, Arg2)
 scasp_json(Arg1, Arg2, Arg3)
Source scasp_human(Arg1, Arg2)
 scasp_dynamic(Arg1)
 scasp_assert(Arg1)
 scasp_assert(Arg1, Arg2)
 scasp_retract(Arg1)
 scasp_retractall(Arg1)
 scasp_abolish(Arg1)
 sld(Arg1)
 describe(Arg1)
 pred(Arg1)
 domain(Arg1)
 #=(Arg1, Arg2)
 #<>(Arg1, Arg2)
 #<(Arg1, Arg2)
 #>(Arg1, Arg2)
 #=<(Arg1, Arg2)
 #>=(Arg1, Arg2)
Source ?(Arg1)
Source ??(Arg1)
Source ?--(Arg1)
Source ?+-(Arg1)
Source ?-+(Arg1)
Source ?++(Arg1)
Source ??+-(Arg1)
Source ??-+(Arg1)
Source ??++(Arg1)
 scasp_readable(Arg1, Arg2)
 scasp_readable(Arg1, Arg2, Arg3)
 portray_model(Arg1)
 portray_model(Arg1, Arg2)
 portray_justification(Arg1)
 portray_justification(Arg1, Arg2)
 html_model(Arg1, Arg2, Arg3, Arg4)
 html_justification(Arg1, Arg2, Arg3, Arg4)
 html_query(Arg1, Arg2, Arg3, Arg4)
 html_atom(Arg1, Arg2, Arg3, Arg4)
 scasp(Arg1)
 scasp(Arg1, Arg2)
 scasp_query_clauses(Arg1, Arg2)
 scasp_query_clauses(Arg1, Arg2, Arg3)
 scasp_directive(Arg1)
 scasp_show(Arg1, Arg2)
 scasp_json(Arg1, Arg2)
 scasp_json(Arg1, Arg2, Arg3)
 scasp_dynamic(Arg1)
 scasp_assert(Arg1)
 scasp_assert(Arg1, Arg2)
 scasp_retract(Arg1)
 scasp_retractall(Arg1)
 scasp_abolish(Arg1)
 sld(Arg1)
 describe(Arg1)
 pred(Arg1)
 domain(Arg1)
 #=(Arg1, Arg2)
 #<>(Arg1, Arg2)
 #<(Arg1, Arg2)
 #>(Arg1, Arg2)
 #=<(Arg1, Arg2)
 #>=(Arg1, Arg2)
 html_model(Arg1, Arg2, Arg3, Arg4)
 html_justification(Arg1, Arg2, Arg3, Arg4)
 html_query(Arg1, Arg2, Arg3, Arg4)
 html_atom(Arg1, Arg2, Arg3, Arg4)
 scasp_readable(Arg1, Arg2)
 scasp_readable(Arg1, Arg2, Arg3)
 portray_model(Arg1)
 portray_model(Arg1, Arg2)
 portray_justification(Arg1)
 portray_justification(Arg1, Arg2)