[PPL-devel] [Fwd: Re: Any Prolog language lawyer out there?]

Roberto Bagnara bagnara at cs.unipr.it
Wed Oct 20 06:52:05 CEST 2004



-------- Original Message --------
Subject: Re: Any Prolog language lawyer out there?
Date: 19 Oct 2004 22:51:02 +0200
From: Jens Kilian <jjk at acm.org>
Organization: 1&1 Internet AG
Newsgroups: comp.lang.prolog
References: <41750912.8040102 at cs.unipr.it> <1098196164.417498 at seven.kulnet.kuleuven.ac.be> <slrncnaat8.jkn.jan at ct.xs4all.nl>

Jan Wielemaker <jan at ct.xs4all.nl> writes:
> >| ?- functor(- 4,X,Y).
> > X = -4,
> > Y = 0 ?
> 
> I think this is a mistake.  Reading "Prolog, the standard", I find
> (p. 230) that an integer is an integer token, which is defined as a
> sequence of digits (besides binary, octal, etc).  If this is really
> true, than negative numbers cannot be represented and only get their
> property when passed to one of the arithmetic predicates.

My copy of a draft version of the standard (ISO/IEC JTC1 SC22 WG17 N110)
says

         6.3.1.2 Negative numbers

                   term = atom, integer;
         Abstract: -n      -      n
         Priority:  0

                   term = atom, float number;
         Abstract: -r      -      r
         Priority:  0

         The prefix operator - with a numeric constant as operand
         denotes the corresponding negative constant.

This explicitly codifies the interpretation of '- 4' seen above.

> I think this is undesirable.  For one thing, on engines using fixed
> with 2-complements representation (allowed!) one must write the
> smallest integer as (-2147483647-1) !?

No.  I can see nothing in the (draft) standard which restricts the range of
an 'integer' token; as I interpret it, a Prolog implementation using 16-bit
integers is free to accept '- 32768' as a valid term and to reject '32768'
as causing an integer overflow.

>  Also, one always needs is/2 to represent a negative integer.

No, the parser has to convert negative numbers.

>  So, the tokeniser should deal with
> '-'{digit}+. The situation for + is a bit less clear as it is not
> _needed_ to represent positive integer terms.

The tokenizer *cannot* consume the '-' in front of a number, because it may
need to be interpreted as an operator. Not even the presence or absence of
whitespace helps:

         X is Y-4.       X is Y - 4.

These must both be interpreted as is(X, -(Y, 4)).

Yes, this sucks.  As does most of Prolog's syntax ;-)

         Jens.
-- 
mailto:jjk at acm.org                 As the air to a bird, or the sea to a fish,
   http://www.bawue.de/~jjk/        so is contempt to the contemptible. [Blake]

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it



More information about the PPL-devel mailing list