From ok@atlas.otago.ac.nz Fri Aug 17 02:23:25 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f7H0NOb27151
	for <prolog@swi.psy.uva.nl>; Fri, 17 Aug 2001 02:23:24 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id MAA73329;
	Fri, 17 Aug 2001 12:23:06 +1200 (NZST)
Date: Fri, 17 Aug 2001 12:23:06 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200108170023.MAA73329@atlas.otago.ac.nz>
To: ai@solvo.ru, prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] Q

"Lyosha" <ai@solvo.ru> wrote:
	If [] is not a list then I would expect is_list([]) to fail.
 	However it succeeds, which
	of course we can treat as an exception. :)
	
What exception?  [] *is* a list.
It is also an atom.  There is nothing new about this.
The empty list in Lisp has also been an atom for the last 40 years or more.

In Prolog, *EVERY* term is a variable, or a number, or it has a function
symbol and zero or more arguments.  (Some Prologs add strings, and some
add "foreign objects".)  Lists are not an exception to this.  An empty
is not a variable, is not a number, and doesn't have any arguments, so
it _has_ to be an atom because there isn't anything else for it to be.

This is book one lesson 2.

	I have another question about lists though.
	
	?- A is [2].
	A = 2
	
	?- A is [4]*[5].
	A = 20
	
	I expected to get an exception when using lists in 'is'.

Had you read the manual, you would not have expected this.


	It's not to be complained about I guess but I am curious - why
	is it happening?  Anyone know?

Anyone who reads the manual or a good Prolog book knows this.  It is
so that you can do arithmetic with characters.  Recall that strings in
Prolog are lists of character codes.  If I want to check whether a
character is a digit, and if so, return its binary equivalent, I could
write

    digit_value(C, D) :-		% ASCII version
	48 =< C, C =< 57,
	D is C - 48.
or
    digit_value(C, D) :-		% EBCDIC version
	16'F0 =< C, C =< 16'F9,
	D is C - 16'F0.

But it is much much clearer to write

    digit_value(C, D) :-		% portable version
	"0" =< C, C =< "9",
	D is C - "0".

I invented the 0' notation in DEC-10 Prolog, so that this can also be
written as

    digit_value(C, D) :-
	0'0 =< C, C =< 0'9,
	D is C - 0'0.

but quite a few Prologs never picked it up.

The rule therefore is that a Prolog system is supposed to accept
	[N]
as an arithmetic expression, where N is an integer.  Prologs are
not required to accept other lists, so
	X is [1+1]
might (Quintus) or might not (SWI) be accepted.

