C#Prolog and other Prolog systems
Prolog has an ISO standard, and C#Prolog follows it in most places. But each Prolog system also has its own extras. When you copy code from a book or from the web, you may find something that C#Prolog doesn't have yet. This page lists the most common cases.
Not available yet
| Feature | What to use instead |
|---|---|
Text in back quotes, such as `hello` |
A quoted atom |
format/2 and format/3 |
write/1, writeq/1, nl/0, and tab/1 |
maplist/2 and its friends |
A recursive predicate, or findall/3 and forall/2 |
read/1 and other input from the user |
Write the input in the query |
Files, open/3, and streams |
The command line tool can load files with consult/1 |
Grammar rules with pushback, such as a, [x] --> b |
Pass the extra words as an argument |
| Constraint libraries, such as CLP(FD) | Generate and test, as in chapter 8 |
| Modules | Choose names that don't clash |
For example, this is maplist/3 written as a normal predicate. You can copy it into your program.
call(G, X, Y) calls the goal G with two more arguments, so call(double, 1, Y) runs double(1, Y).
Small differences
- A query shows
trueand waits. After an answer, C#Prolog always offers to look for the next one, even when there is none. Other systems often know that there are no more answers, and end the query at once. - Library predicates can be replaced. If you define
append/3ormember/2yourself, your version replaces the one of C#Prolog. Other builtin predicates, such aslength/2, can't be redefined. - Text in double quotes is a list of codes.
"hi"is[104, 105]by default, as the ISO standard says. Set the flagdouble_quotestocharsoratomto change it, as chapter 15 shows. SWI-Prolog reads double quotes as its own string type, which C#Prolog doesn't have. /always gives a float.X is 4 / 2gives2.0, as the ISO standard says. Some systems give the integer2in this case.- Error messages. Errors are shown as the error term, such as
ERROR: error(instantiation_error,_G1).
The list of builtin predicates has the details of each predicate.
What to read next
- Learn Prolog Now! is a free online book. It covers the same ground in more depth.
- The SWI-Prolog manual describes many predicates that are common in Prolog systems.
- "The Art of Prolog" by Leon Sterling and Ehud Shapiro is a classic book about programming in Prolog.
- To use C#Prolog from your own .NET program, read Getting started and the C# API.