Article View: comp.lang.prolog
Article #3055Re: BSI syntax
From: Richard A. O'Keefe
Date: Thu, 10 Mar 1988 07:59
Date: Thu, 10 Mar 1988 07:59
128 lines
6243 bytes
6243 bytes
In article <1175@kulcs.kulcs.uucp>, bimbart@kulcs.uucp (Bart Demoen) writes:
> I hope the "detailed response" will not consist of excerpta from half of the
> programs of R. O'Keefe, but I am afraid it will ...
> But less egocentric comments on Chris Moss's recent posting, I am interested in.
D'y'know, playmates, I get the feeling that he doesn't like me. Sniffle.
Here is a list of Prologs which are more similar to each other than any
of them is to the BSI syntax:
DEC-10 Prolog,
C Prolog,
Quintus Prolog,
SICStus Prolog,
Stony Brook Prolog,
ALS Prolog,
Arity Prolog.
I haven't any documentation on PopLog, but when I last used it in 1984
it used 8-bit priorities as did NU7 PDP-11 Prolog (but there is some way
of making it use DEC-10 Prolog compatible numbers) and had fancy syntax
for call/N (I think it was Pred$(X,Y,Z) where Quintus Prolog would use
call(Pred, X, Y, Z)). In both respects it departs from the BSI syntax.
Apart from those respects, it was then more similar to DEC-10 Prolog than
to the BSI syntax.
I don't mind converting my own code. But my salary ultimately comes out
of the pockets of people who buy Quintus Prolog, and a lot of them buy
our Prolog because it hews so close to the Edinburgh line. Does defending
the interests of these people really count as "egocentricity"? Really?
Does saying that the BSI Prolog committee has no divine mandate to break
Lee Naish's code constitute "eogcentricity" on my part? Does commending
Arity Prolog's solution to the string/character-list problem? AAIS Prolog
for the Macintosh is very different from Edinburgh Prologs (for example,
the body of a clause is converted to a list) but they have provided enough
hooks to customise their tokeniser so that you can get very close to
Edinburgh syntax. I claim that AAIS have taken a responsible approach to
such syntax changes, and that the BSI comittee ought to study the AAIS
Prolog manual very carefully. Is it "egocentric" of me to say that?
Perhaps Bart Demoen thinks it egocentric of me to express any opinions at all.
A word of warning: Chris Moss's posting was two pages out of 25. Many of
my comments were directed at aspects of the grimoire not covered in that
posting. I think the topic is of sufficient interest to warrant posting
the entire thing, but that's for the BSI committee to do/authorise.
A big problem with the grimoire is that it is presented as a grammar for
_program_ _files_, not as a grammar for terms. For example, rule 0 of
the grimoire is
0 file :- tokens, program ;
Input Chars Chars Tokens
Output Abstract Tokens Abstract
and the accompanying text says
"the production 'tokens' converts a list of characters to a list of
tokens. The production 'program' converts that list to a tree
which represents the abstract syntax of the program."
That is, what is defined is a mapping from entire files to trees
(specifically, a file is mapped to a list of clauses).
Did you notice that this leaves read/1 undefined?
We don't need a grammar for Prolog. We need a definition of read/1, and
a definition of what a term means when considered as a clause. That
will be of some use to someone who writes a parser for some different
input language, but the present grimoire will not.
Here is something you can do in some Prolog systems. (You could not do
it in compiled Dec-10 Prolog, and you can only do it with extreme
difficulty in Quintus Prolog.) Suppose you want an analogue of C's #if.
facility. Then you can, in some Prolog systems, define
if(Condition) :-
( Condition -> true ; read(_) ).
and then
:- if( 1 = 1 ).
<term>.
will leave <term> in the input stream for compile/1 or consult/1 to
notice, but
:- if( 1 = 2 ).
<term>.
will consume <term> so that compile/1 or consult/1 will never know it
had been there.
The grimoire forbids this, which won't make Quintus particularly sad.
The trouble is that it is not clear that the committee ever thought of
it. It's not one of the Syntax Issues that accompanies the grimoire.
The grimoire doesn't explicitly forbid it, but implicitly, because it
defines a meaning for the file which always includes both the call to
if/1 *and* the following term.
Here's another example of the same kind, only worse. In some of my
Pop-2 programs, I used to write
until .cucharin = ## do enddo;
<commentary>
#
Now, in some Prolog systems, you can do the same sort of thing:
:- skip(0'#).
<commentary>
#
where the stuff between the command and the sharp sign can be any old
sequence of characters, and need not follow Prolog syntax. The grimoire
clearly forbids this: an entire file _must_ be a sequence of clauses.
Bearing in mind that this can't be done at all in compiled DEC-10 Prolog,
and that it requires low cunning and much effort to do in Quintus Prolog,
I'm certainly not going to argue that the standard should _require_ all
implementations to permit source files to skip parts of themselves. But
there are good reasons why someone might want to do this, so I think the
standard should be so constructed as to _permit_ it. (The difficulty in
Quintus Prolog is finding the right stream, not doing the skipping.) It
is surely clear that someone reading a file of data might want to use
read/1 for some things and get0/1 for others _in the same file_, but the
grimoire makes no provision for that.
As it is currently phrased, there is nothing in the grimoire to stop a
source file closing itself:
:- seeing(X), seen.
That doesn't matter. The grimoire still says quite clearly that the
whole file must be processed.
Prolog is the same kind of language as Lisp or Pop. Common Lisp is not
defined by giving a grammar for "programs" (there being no such animal).
It is defined by defining 'read'. That's how to define Prolog.
Technical Details
Message-ID:
<749@cresswell.quintus.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!sri-unix!quintus!okReferences:
<1175@kulcs.kulcs.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: BSI syntax Message-ID: <749@cresswell.quintus.UUCP> Date: 10 Mar 88 07:59:06 GMT References: <1175@kulcs.kulcs.uucp> Organization: Quintus Computer Systems, Mountain View, CA Lines: 128