All Manuals > KnowledgeWorks and Prolog User Guide > Appendix A: Common Prolog

A.4 Using The Logic Interpreter

The Common Prolog system comes with a built-in read-query-print loop similar to a Prolog interpreter loop. To run it, make sure the common-prolog package is accessible and type: (rqp). You will be presented with the prompt: ==>. At this point you may type in goal expressions, for example:

|==> (append ?x ?y (1 2))
|
|?X = NIL
|?Y = (1 2)

Now Common Prolog is waiting for you to indicate whether or not you wish more solutions. If you press Return, you will get the message OK and return to the top level:

|?X = NIL
|?Y = (1 2)<RETURN>
|
|OK.
|
|==>

A.4.1 Multiple Solutions

If you hit ; (semicolon) following the retrieval of a solution, the system will attempt to resatisfy your goal:

|?X = NIL
|?Y = (1 2);
|
|?X = (1)
|?Y = (2);
|
|?X = (1 2)
|?Y = NIL;
|
|NO.
|
|==>

When no more solutions remain, NO. is displayed and you are back at the top level.

A.4.2 Multiple Goals

To request the solution of multiple goals, use: (and <goal1> ... <goalN>).

For example:

|==> (and (member ?x (2 3)) (append (?x) (foo) ?y))
|
|X = 2
|Y = (2 FOO)
|
|OK.
|
|==> 

A.4.3 Definitions

It is possible to type logic definitions directly into the interpreter. The resulting Lisp code will be compiled in memory and you may use the definition immediately, for example.:

|==> (defrel color
|      ((color red))
|      ((color blue))
|      ((color green)))
|
|<... various compilation messages ...>
|
|YES.
|OK.
|
|==> (color ?x)
|
|?X = RED

A.4.4 Exiting the Interpreter

The Common Prolog interpreter may be exited by typing:

|==> (halt)

KnowledgeWorks and Prolog User Guide (Windows version) - 01 Dec 2021 19:36:05