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

NextPrevUpTopContentsIndex

A.2 Syntax

Common Prolog uses a Lisp-like syntax in which variables are prefixed with "?" and normal Lisp prefix notation is used. Goals are represented as either lists or simple vectors e.g. (reverse (1 2 3) ?x) or #(member ?x (1 2 3)). A symbol beginning with ? may be escaped by prefixing another ?.i.e. ?foo is the variable named foo; ??foo is the symbol ?foo.

The definition of append/3 from Prolog:

  append([], X, X).
  append([U|X], Y, [U|Z]) :-
          append(X, Y, Z)

translates to:

  (defrel append
    ((append () ?x ?x))
    ((append (?u . ?x) ?y (?u . ?z))
     (append ?x ?y ?z)))

Unlike many Lisp-based logic systems, Common Prolog uses simple vectors to represent Prolog structured terms. Thus, functor, arg, and =.. all behave in a standard fashion:

(arg 2 (foo 3 4) (3 4))
(arg 2 #(foo 3 4) 4)
(functor (foo 3 4) \. 2)
(functor #(foo 3 4) foo 2)
(=.. #(foo 3 4) (foo 3 4))
(=.. (foo 3 4) (\. foo (3 4)))

KnowledgeWorks and Prolog User Guide (Unix version) - 26 Feb 2015

NextPrevUpTopContentsIndex