Prev Next Up Home Keys Figs Search New

Syntax

Appeared in Volume 6/3, August 1993

Keywords: syntax.

jamie@cs.sfu.ca
Jamie Andrews
11th March 1992

Jocelyn Paine writes:
I'm curious about how the syntax of Prolog came to be the way it is. In particular (in Edinburgh syntax): why is comma used for "and" as well as an argument separator

This comes from the view of the clause as a set of literals rather than a sequence of conjuncts or disjuncts; this in turn arises from the natural view of clauses in resolution theorem proving. The comma notation appears in Kowalski's 1974 paper, and also in Absys (Elcock and Foster's 1968 precursor of Prolog). The set-based view of clauses informs the traditional procedural semantics and model theory of LP as well. (see Lloyd)

Paine writes:
why are predicate names written in lower case and variables in upper case, the reverse of the usual mathematical notation.

The distinction is perhaps better drawn between variables and function symbols. There needs to be some distinction between these two kinds of expression:

function	variable	example
tree		Tree		Tree = tree(Tree1, Tree2)
Tree		tree		tree = Tree(tree1, tree2)
%tree		$tree		$tree = %tree($tree1, $tree2)
I think I would decide on the first one too, for efficiency reasons and for the fact that we more often want variables (rather than function symbols) to jump out at us from the program text.

pereira@alice.att.com
Fernando Pereira
13th March 1992

David H. D. Warren designed the syntax; I participated in some discussions on it, but my recollections are unfortunately pretty vague.

Paine writes:
how did ":-" come to be used for implication. Can someone explain this, or point me at a suitable reference on the history?

I think I remember this one. One consideration was readability: on many printers of the time, <- looked pretty bad, because the - did not align with the vertex of the < or was overwhelmed by it. Also, I seem to remember something about avoiding shift characters for easier typing, but I'm no longer sure because on the keyboards I see here : is a shift character.

ok@goanna.cs.rmit.oz.au
Richard A. O'Keefe
17th March 1992

Paine writes:
why are predicate names written in lower case and variables in upper case, the reverse of the usual mathematical notation.

I think it is important to realise that there is no usual mathematical notation. For example, when I was taught Linear Algebra, we used: lower case letters for scalars; decorated letters for vectors; capital letters for linear transformations (matrices, functions); special punctuation marks (||, x, ., +) for the functions.

Much of Prolog syntax follows English syntax. Even the variable/constant distinction in Prolog follows English convention. Common nouns and adjectives (which are like functions and predicates) receive lower case, whereas proper nouns (including "generic" nouns like A and B) receive upper case.

The real way that "usual mathematical notation" distinguishes reliably between variables and constants is through the use of explicit declarations: "let A be Avogadro's number ...", or "let G: C -> C be the generating function of gn ...", or even "[[universal]]x.p(x)".

powers@kub.nl
David Powers
17th March 1992

It's hard to argue with Fernando's recollections, but I'd always heard that it was a relic of the original Colmerauer and logical underpinings of Prolog:
+a, -b, -c. -> a :- b, c.

A set of clauses is a conjunctive normal form, a conjunction of disjunctions, both in list/set form.

That is comma (',') is/was disjunction, and every literal was marked as either positive or negative. In Horn clauses there is only one literal, so a colon (':') separated the positive and negative literals with a minus sign ('-') marking the negated context (in which comma now seems to evince conjunctive semantics.

pereira@alice.att.com
Fernando Pereira
18th March 1992

Unfortunately for your theory, the syntax of clauses in the Fortran-based Marseilles interpreter did not involve comma; your clause above would be written:
+A -B -C.

Lower case wasn't available then. In addition, I know for sure that :- was intended as a notation for "if". Another historical snippet is that the Edinburgh syntax went through an intermediate stage in which it was upper-case only (upper/lower case printers and terminals were not widely available at the Edinburgh AI Dept before the late 70's). Here are a few clauses in that syntax extracted from David Warren's revised top-level for the Marseille interpreter:

WRITE((_X)) :- VAR(_X), !, WRITE1(_X).
WRITE((_X;_Y)) :- !, WRITE(_X), NEWLINE, WRITE(_Y).
WRITE((_X;)) :- !, WRITE(_X), NEWLINE.
WRITE((_X,_Y)) :- !, WRITE(_X), WRITE(_Y).
WRITE((_X)) :- WRITE1(_X).
This syntax, extended with lower case and a few other things, was then used for the Edinburgh DEC-10 compiler.

Prev Next Up Home Keys Figs Search New