🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1854

Re: Prolog parser bug in reading conditional? Or not?

#1854
From: Richard A. O'Keefe
Date: Tue, 26 Feb 1991 05:16
57 lines
2784 bytes
In article <1991Feb22.172635.16587@and.cs.liv.ac.uk>, dave8@and.cs.liv.ac.uk writes:
    > If the following is entered during a consult/1 ...
[*] >   a( X ) :- ( true -> X = 1 ) ; X = 2 .
    > then, when it is listed, it appears as
[a] >   a( X ) :- ( true -> X = 1 ; X = 2 ) .
    > or
[b] >   a( X ) :- true -> X = 1 ; X = 2 .

Stop and _think_.  Parentheses in Prolog have *NO* semantic effect,
they are *solely* a device for controlling grouping.  It follows that
	( P -> Q ) ; R
*MUST* be the data structure
	;( ->( P, Q ), R )
and it is this data structure which bears the meaning "if then else",
*not* the surface syntax.  [*], [a], and [b] are all equivalent ways
of expressing exactly the same term.  I regard [b] as the "correct"
output for write/1, as it contains nothing superfluous.
[a] has superfluous parentheses around the "_;_", they do no harm,
and the listing/1 and portray_clause/1 implmentations I am responsible
for would write something like
[c]	a(X) :-
		(   true ->
		    X = 1
		;   X = 2
		).

But you could just as well write
[d]	a(X) :- ;(->(true,=(X,1)),=(X,2)).
and it would *be* the same term as [*], [a], [b], or [c].

> I would have thought that this was a bug, but is it?

Not at all.  read/1 is doing precisely what it *must* do!
Apart from being infix operators, :-, ->, and ; have no special
meaning to read/1, and assert/1 or its compiled equivalent *must*
not give a tinker's about what the source form happened to look like.

> However, if you enter (the workaround) (I did want to use code like
> the above but obviously replacing "true" with some predicate) ...
>   b( X ) :- ( true -> X = 1 ; fail ) ; X = 2 .

I am rather puzzled as to why anyone would want the effect of
	call((P -> Q)) ; R
can you show us what you were trying to do?  Another possibility
would have been to write
	((P -> Q), true ; R)	;(','(->(P,Q),true),R)
or	(true, (P -> Q) ; R)	;(','(true,->(P,Q)),R)

The rule of thumb is to never use P->Q on its own.  This is doubly
advisable because there are otherwise excellent Prolog systems
which interpret a bare P->Q as P->Q;true.

> Is this a parser problem or not?

No, it is a parser WORKING.
-- 
The purpose of advertising is to destroy the freedom of the market.
Technical Details
Message-ID: <4826@goanna.cs.rmit.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!usc!samsung!munnari.oz.au!goanna!ok
References: <1991Feb22.172635.16587@and.cs.liv.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!usc!samsung!munnari.oz.au!goanna!ok
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.prolog
Subject: Re: Prolog parser bug in reading conditional? Or not?
Summary: not a Prolog mistake
Message-ID: <4826@goanna.cs.rmit.oz.au>
Date: 26 Feb 91 05:16:47 GMT
References: <1991Feb22.172635.16587@and.cs.liv.ac.uk>
Organization: Comp Sci, RMIT, Melbourne, Australia
Lines: 57