Command line tool
CSProlog.Cli is a .NET tool with an interactive Prolog console, like the top level of other Prolog systems.
Running it
Run it without installing it.
dnx CSProlog.CliOr install it, and run the csprolog command.
dotnet tool install -g CSProlog.Cli
csprologQueries
Type a query that ends with a period. A query can span several lines. After each answer, press ; for the next answer, or Enter to stop.
?- member(X, [a, b]).
X = a ;
X = b ;
false.false.means that there is no more answer.- An error is shown as
ERROR:and the error term. - Ctrl+C stops a running query.
- The arrow keys bring back earlier input. The history is saved in
~/.csprolog/history. halt.or Ctrl+D ends the console.halt(N).ends it with the exit codeN.
Tracing
trace. turns on tracing, and notrace. turns it off. spy(Name/Arity). traces only that predicate. While tracing, the console shows each step of a call and waits for a key.
?- trace.
true.
?- member(X, [a]).
Call: (1) member(_G1,[a]) ? creep
Exit: (1) member(a,[a]) ? creep
X = a.| Key | Action |
|---|---|
Enter, c, or space |
Goes to the next step (creep). |
s |
Skips the steps inside this call. |
l |
Turns off tracing, and goes on until a spy point (leap). |
a |
Stops the query (abort). |
Call, Exit, Redo, and Fail are the ports of the call. The number in parentheses is the depth of the call. With redirected input, the console shows the steps and does not wait.
Files
Files given on the command line are consulted first.
csprolog family.plIn the console, consult(family). and [family]. consult a file. A file name without an extension also tries .pl.
Adding clauses as you type
With --input-mode consult, the console adds what you type to the database, and shows what was added. Input that starts with ?- is still a query. The prompt is |: in this mode.
|: human(socrates).
Added 1 clause to human/1.
|: ?- human(X).
X = socrates ;
false.Options
| Option | Description |
|---|---|
--input-mode query |
Treats all input as queries. This is the default. |
--input-mode consult |
Adds input to the database. Input that starts with ?- is a query. |
--help |
Shows the help. |
--version |
Shows the version. |
dnx itself also has options such as --version and --help. To pass them to the tool, put -- before them.
dnx CSProlog.Cli -- --versionRedirected input
When the input is not a terminal, the console shows no prompt and waits for no key. It shows all the answers of each query, and ends at the end of the input.
echo "member(X, [a, b])." | csprolog