Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.prolog Subject: WG17 against Sterling and Shapiro Keywords: standard books changes Message-ID: <2655@munnari.oz.au> Date: 8 Nov 89 12:36:51 GMT Sender: news@cs.mu.oz.au Lines: 404 WG17 against Sterling and Shapiro --------- an evaluation --------- I have complained, for several years now, that the BSI committee and now WG17 do not seem to regard other people's work as important. I have had in mind other people's programs,but that's not the only kind of work that deserves to be protected. A particularly important class of work I believe should be protected is Prolog textbooks, not that there are many of *those* that I like. With respect to textbooks,there are three kinds of people who will be hurt by a standard which differs too much from the descriptions in the books: (a) the publishers, whose current offerings will be diminished in value (b) the authors, who will either have to produce new editions of their works, or see their books decline in the market as no longer relevant (e.g. John Stobo's book, which was to a large extent based on the standard as it stood when he wrote, now no longer reflects *either* the standard *or* an existing Prolog) (c) the purchasers, who bought books which _did_ describe Common Prolog, but who will have to purchase additional books if they want something that describes the standard. I wonder whether it would somehow be possible for the publishers (such as Springer-Verlag, MIT Press, Prentice-Hall, and one or to others) to have a representative on the ISO committee -- it seems to me that they have done more for the Prolog community than the committee have, and definitely deserve to have their interests represented. In this case their interests (continued markets for their books) coincide with their authors' interests and ours. To demonstrate that there is a real threat to existing worthwhile books, I thought it would be appropriate to look at Appendix B of Sterling and Shapiro's "The Art of Prolog". It has to be admitted that some of the predicates they describe there are specific to Wisdom Prolog. In the table which follows, I've labelled such predicates "private", others are labelled "common". GRAMMAR RULES common DELETED atom/1 common present (used to be broken, ok now) integer/1 common present atomic/1 common present constant/1 private functor/3 common present arg/3 common modified var/1 common present nonvar/1 common present Note: the change to arg/3 is that in arg(N,Term,Arg), if N < 1 or N > arity(Term) an error MUST be signalled instead of the former quiet failure. This contradicts explicit statements in S&S, and more importantly it is incompatible with the explanation in S&S that "The predicate is defined as if there were an infinite table of facts." Here is an example of a predicate which would be *broken* by this change: % sub_term(Kernel, Term) % is true when Kernel is a sub-term of Term. sub_term(Term, Term). sub_term(SubTerm, Term) :- nonvar(Term), functor(Term, _, N), sub_term_scan(N, Term, SubTerm). sub_term_scan(N, Term, SubTerm) :- arg(N, Term, Arg), sub_term(SubTerm, Arg). sub_term_scan(N, Term, SubTerm) :- N > 1, M is N-1, sub_term_scan(M, Term, SubTerm). This code is not found in Sterling & Shapiro, but according to the definition of arg/3 found on p138 it is perfectly legal. In WG17's N40, it _MUST_ break. If N40's definition is adopted, you will not be able to use Sterling & Shapiro as a guide. assert/1 common DELETED (new incompatible assert/2) asserta/1 common DELETED (new incompatible asserta/2) assertz/1 common DELETED (new incompatible assertz/2) retract/1 common DELETED (new incompatible retract/2) abolish/2 common DELETED (new incompatible abolish/1) Note: I personally strongly dislike abolish/2, as it is inconsistent with other DEC-10 Prolog operations. The general convention is that a meta-predicate which is free of side effects takes a single predicate specification in the form of a term which looks like a call to that predicate, e.g. current_predicate(_, foo(X,Y,Z)) is true if foo/3 is a user-defined predicate, while a meta-predicate which changes the state of the system in any way takes an argument which specifies a set of predicates. So abolish/2 is NOT consistent with this convention, and N40's abolish/1 -- which presents the same interface as Quintus's abolish/1 *IS* consistent with this convention. This is just about the only case where I like N40's version better than what is common. Unfortunately, my likes and dislikes really don't matter; abolish/2 _is_ the Common Prolog operation and abolish/1 _isn't_. It is fair enough to add abolish/1 and recommend that abolish/2 should no longer be used, but it is _not_ fair enough to delete abolish/2. Worse still, N40's particular version of abolish/1 cannot be used to implement abolish/2: abolish(F, N) :- abolish([F/N]). won't work because the former abolishes static predicates and the latter does not (in N40, that is; in Quintus Prolog it works just fine). consult/1 common CHANGED reconsult/1 common CHANGED [...] common DELETED Note: Quintus Prolog and some others have deleted consult/1 and renamed reconsult/1 to consult/1. This one is debateable. Note: that's not what N40 changed, though. N40 changed the argument from a file name to a stream. clause/2 common present listing/0 common present listing/1 common present read/1 common present Note: Sterling and Shapiro do not describe Prolog syntax in detail. N40 DELETES character lists, which does break S&S, but that's one of the few explicit differences. sread/2 private provided as read_with_names/2 Note: this operation was present in the public-domain implementation of DEC-10 Prolog syntax as read/2; it was also provided in some versions of C-Prolog as read/2, and is in the Quintus library as portable_read/2. A similar operation is in NU Prolog as readTerm/3. The name and interface in N40 are quite sensible, and as this is one of the areas where there was no agreement, I think read_with_names/2 is a Good Thing. write/1 common present (vague) writeq/1 common present (vague) display/1 common present (vague) displayq/1 private print/1 common modified (probably unintentional) Note: in Common Prolog, if you call print(f(X,Y)), and your definition of portray/1 does not match f(X,Y), print/1 then checks to see whether 'f' is an infix operator. If it is, it will print(X), write f suitably, and print(Y), possibly with parentheses around the whole. But N40 states clearly in 9.12.2.1 c) that the principal function symbol must be printed first and then the arguments, and there is no exception for infix or postfix operators. Thus if there is no portray rule which matches A true ). It can be coded in WG17 Prolog as iterate(Goal) :- call( (repeat, fail_if(Goal), !) ). or as iterate(Goal) :- once( (repeat, fail_if(Goal)) ). I can't think of a good use for it, but it's definable, so no harm done. fork_exec/2 private Note: this is not listed in the index of S&S and the text does not appear to describe it. It sounds OS-dependent, whatever it is. ancestor/2 private cutg/1 private retry/1 private Note: these operations are apparently used in the WISDOM Prolog debugger. There is a Common Prolog predicate ancestors/1 in terms of which ancestor/2 is definable. cutg/1 is a form of ancestral cut. Debugging is outside the scope of the standard, and other Prologs use different support predicates. < /2 common modified := /2 private is /2 common modified Note: := /2 is a private alias for is/2. I dislike it on the grounds that it doesn't behave like assignment, so why make it look like assignment? WG17 Prolog permits the right hand side of is/2 to be a string, so you can say X is $foo$. Earlier drafts had several string functions which have been replaced by cleaner and better predicates (still not as good as the ones in Xerox Quintus Prolog...), so this may just be a relic of the past. Arithmetic comparisons may have strings in them, but must then always fail, again this appears to be a relic of the past. Apart from strings, arithmetic expressions in WG17 Prolog are mostly an extension of expressions in Sterling & Shapiro. -------- ------ ---- -- Summary. If Sterling and Shapiro want to make their book compatible with WG17 Prolog as it currently stands, they will have to make changes to every chapter. My estimate is that roughly a quarter of the text will need to be rewritten, though all of it will have to be checked carefully. The amount of labour involved is roughly comparable to the amount of labour required to convert an elementary Pascal textbook to an elementary Modula-2 textbook.