Re: A quirk in the syntax of Prolog



Feliks <feliks.kluzniak@xxxxxxxxxxxx> writes:
A Quirk in the syntax of Prolog
....
Are we really being kind to the user by supporting such a surprising
and ambiguous convention?

Prolog programmers tend to avoid syntax issues and consider it a
windmill fight for the dragon book. Nevertheless, these issues hit us
unexpectedly from time to time. Here is one in the line of your
examples but with predefined operators only:

SICStus 3, YAP, B-Prolog:

f(dynamic-static) == f(-(dynamic,static)).

but

f((dynamic-static)) == f(dynamic(-(static))).

So within the argument list of f/1, a further pair of brackets for an
argument changes the argument's meaning.

SWI and ECLiPSe:

f(dynamic-static) == f(dynamic(-(static))).

but

f(static-dynamic) == f(-(static,dynamic)).

ISO 13211-1:1995 (ISO Part 1) cleaned up most of the ambiguous issues.
All cases above are rejected if dynamic is prefix, except for the one
with double brackets. GNU Prolog behaves that way ; XSB almost. Note
that ISO does have a dynamic/1 directive but no corresponding operator
declaration.

In my own opinion it is time to let go of it as quickly as possible.
What do you think?

What is missing in most systems is a way to enforce strict syntax.
IF/Prolog has it as required by 5.1 e. But this mode has to remove
all other implementation specific extensions at the same time. GNU
Prolog's syntax seems strict (not sure). But most implementations
still permit many implementation specific extensions for the sake of
backwards compatibility, but without the option for a strictly
conforming mode. Ideally, there would be a flag similar to the
frequently supported flag character_escapes.

Is there a significant and useful subset of the current syntax
extensions w.r.t. 13211-1's operators where many Prolog systems agree
with each other? Maybe there is one, but it will be difficult to
define precisely. In fact, ISO tried exactly this and it took quite
some time to reach the status quo. In 7.8.6 - 7.8.8 you can see the
remnants of that quest: E.g. ';'(E, O). can be written more
compactly as ;(E, O).

So what is the cost of enforcing strict syntax (optionally)? Some
predicate indicators would have to be written with extra brackets.
I.e. (is)/2 in place of is/2. Just noted such an issue in SWI's
library(clpfd) which tries to fit into the ISO system.

On the other hand, the nice properties of the ISO syntax are still not
very well known and exploited:

For one, there is the functor notation that can be read in regardless
of the operator table present. Also, the compact list notation can be
used with them.

And atoms as arguments of functors or lists never need brackets - no
matter what operator declarations are in effect. Maybe such
unnecessary brackets could be highlighted as a syntax warning?
.



Relevant Pages

  • Re: Oracle outer join syntax (+) not working???
    ... has been that the join operator was the ISO standard prior to ISO ... I find that SQL Validator is a good place to check: ... It is not just an Oracle syntax. ...
    (comp.databases.oracle.misc)
  • ISO Modula-2 "gotcha"
    ... FYI, but perhaps not too significant practical, I spent some hours recently ... turned out to be a "gotcha" in ISO M2. ... I realized that it was the unary minus syntax. ...
    (comp.lang.modula2)
  • Re: [OT] Java rules
    ... die den Anforderungen einer ECMA / ISO auch nur ansatzweise genügen würde. ... Semantik ausreichend genau definiert werden konnten. ... Wenn dort Syntax und Semantik nicht ... Verlust keinen ECMA Standard zu sein. ...
    (de.comp.lang.java)
  • Re: Why multiplication not allowed?
    ... >> questions the interviewer asked me was to tell him what was wrong with the ... >> Afterwards I wondered whether this might have been some kind of syntax left ... AFAIK they were dropped when ISO ... Not many years ago, I used a compiler that allowed the ...
    (comp.lang.c)
  • Re: Buggy SQL Syntax for External File Path in Access 2007
    ... Parentheses around the sub-select are turned into square brackets ... AS Alias is Jet SQL's syntax for derived tables. ... One option you might consider is setting your database to use ANSI ... 92 SQL, which will mean that you can use the standard AS Alias ...
    (microsoft.public.access.modulesdaovba)

Loading