This is an old revision of the document!


Using Prolog for reasoning

This is a short REPL tutorial to demonstrate the usage of CRAM Prolog engine for solving reasoning tasks.

CRAM has its own primitive Prolog interpreter written in Common Lisp which can work natively with the Lisp data structures (as opposed to, e.g., SWI Prolog, which would need a complex mechanism for passing around Lisp data structures and converting Prolog results back into Lisp). It is implemented in the “cram_reasoning” package, so, first of all, let's load the package:

CL-USER> (asdf:load-system :cram-reasoning)
CL-USER> (in-package :cram-reasoning)

Executing Prolog queries is done by calling the prolog function, where its first argument is a list of symbolic data:

CRS> (prolog '(member ?x (1 2 3)))
(((?X . 1))
 . #S(CRAM-UTILITIES::LAZY-CONS-ELEM :GENERATOR #<CLOSURE # {100A55B86B}>))

This query means: find such a binding (assignment) for the variable ?x such that the statement “?x is a member of the list (1 2 3) would be true. Obviously, there are multiple bindings for ?x that satisfy the statement, namely, 1, 2 or 3 are all valid assignments for ?x.
Sometimes there can be very many valid bindings for a variable or even an infinite amount of solutions. Thus, CRAM Prolog interpreter returns the bindings as a lazy list and not a normal list. A lazy list returns per default one value at a time and uses a generator function to spit out more values when required.