Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: Ranges of values in Cprolog Message-ID: <950@cresswell.quintus.UUCP> Date: 9 May 88 03:35:40 GMT References: <242@yetti.UUCP> <451@cmx.npac.syr.edu> <944@cresswell.quintus.UUCP> <467@cmx.npac.syr.edu> Organization: Quintus Computer Systems, Mountain View, CA Lines: 71 In article <467@cmx.npac.syr.edu>, hamid@hilbert.uucp (Hamid Bacha) writes: > In article <944@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: > >In article <451@cmx.npac.syr.edu>, hamid@hilbert.uucp (Hamid Bacha) writes: > >In an Edinburgh-compatible Prolog, "-is a special case; the > >"-" here is the tightest binding operator and is not disabled by > > :- op(0, fy, -). > >which cancels the usual unary minus. Thus after doing > In C-Prolog (version 1.5) unary '-' is defined as op(fx, 500, -) and does > not bind tighter than operators with higher precedence (lower precedence > number). It is treated as a special case in that -1 is negative integer 1 > instead of -(1). A simple example using C-Prolog proves it: (1) Surely that's op(500, fx, -). > C-Prolog version 1.5 > | ?- op(400, xfx, ..). > | ?- assert(p(-1 .. 2)). > | ?- p(-X). > X = 1..2 > This is clearly different from '..'(-1,2) which Richard claims it should be. > The same behavior is observed with ALS-Prolog (the other system I have > access to in addition to our own Columbus Prolog and MetaProlog). (2) If this really is the case, it is a bug. (C Prolog is known to take a few short-cuts with operators.) The test case which is supposed to make it all clear is x^ -2 If current_op(200, xfy, ^) and current_op(500, fx, -) (as is normally the case), this would be illegal, and you should find that x^ -y IS illegal. - being a special case, however, x^ -2 means the same as x^ (-2). (3) Believe it or not, there is method in't. The idea is to simplify the *output* routines. We would like writeq(X) to be able to say "oh, X is a number, I'll just write it", whatever the surrounding context, rather than sometimes having to write a negative number as (-4) or whatever. It could be argued that having - treated specially is a bad idea, and that it would be better to have it parsed as an ordinary operator and then treated specially when operator and operand are combined. However, in DEC-10 Prolog, all operators can have their priority reassigned, and all operators can be cancelled by assigning priority 0, so there has to be something special about - or it would be possible to get into a state where negative numbers could not be entered. (4) I have just received a copy of ALS Prolog version 1.0 for the Macintosh SI and MAc II. I tried write(-(5)) and writeq(-(5)) in it. Both printed "-5", which is quite wrong. writeq/1 is supposed to write something so that it can be read back, so writeq(-(5)) ought to write -(5) or (-(5)) or '-'(5) or -((5)) or - (5) or almost anything BUT -5. I think it's fair to call this a bug. ALS Prolog fails to report the syntax error in (x^ -y) although this is clearly illegal according to the table on p42 and the last two paragraphs of section 5.7. While it does indeed parse -1..2 (incorrectly) as -(1..2), it parses 1.. -2 as ..(1,-2) which ought to be illegal if - doesn't have lower rank than .. . This inconsistency does not seem desirable. There is much to admire in ALS Prolog, and I don't want to give anyone a bad impression of it. I just want to point out that its I/O is (in this *specific* release) at least as buggy as that of C Prolog, and it should not be cited to prove what "Edinburgh syntax" is. [That is what the public-domain parser is for.]