Subject: Re: [SWIPL] element=singleton list

From: "Richard A. O'Keefe" <[email-masked]>
Date: Thu, 8 Feb 2001 14:08:16 +1300 (NZDT)

"Bouquard Jean-Louis" <[email-masked]> asked:
	
	How do you explain the confusion between a number N
        and a list of a number [N]?

The same way that you explain the confusion between a number N and
the expression +N.

There is, in short, NO CONFUSION whatsoever.
Just as Fortran and Algol and PL/I and Pascal and C and most programming
languages have a unary + operator that does nothing, so Prolog has a
[ _ ] operator in expressions, that does nothing.

Recall that DEC-10 Prolog very sensibly defined a string to be a list of
character codes, so "A" is [65] and "Z" is [90].  In order to do arithmetic
on characters, as practical programs all must, somewhere, the definition
of arithmetic expressions says that a list of one character code IS NOT
but EVALUATES TO the numeric value of that character.

Thus

    is_ascii_upper_case_letter(C) :-
        "A" =< C, C =< "Z".

This proved a bit awkward, so in DEC-10 Prolog the notation was superseded
by radix 0.  Prolog integers can be expressed in non-decimal bases as
	<radix>'<extended digits>
e.g., 8'177, 16'FED.  Radix 0 is character codes, so one can write

    is_ascii_upper_case_letter(C) :-
        between(C, 0'A, 0'Z).

However, the old feature in arithmetic expressions was not removed;
unlike the ISO Prolog committee we didn't see any point in breaking
existing working code.

So the fact that [2] evaluates to 2 (IN AN ARITHMETIC EXPRESSION ONLY)
is no more surprising than the fact that +2 evaluates to 2, and a lot
more useful.