From jan@swi.psy.uva.nl Fri Jan 18 12:07:39 2002
Received: from there (jan@gollem.swi.psy.uva.nl [145.18.152.30])
	by swi.psy.uva.nl (8.11.6/8.11.2) with SMTP id g0IB7dT25102;
	Fri, 18 Jan 2002 12:07:39 +0100 (MET)
Message-Id: <200201181107.g0IB7dT25102@swi.psy.uva.nl>
Content-Type: text/plain;
  charset="iso-8859-1"
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: =?iso-8859-1?b?Pz8/Pz8/PyA/LiA/Pz8/Pz8/?= <dima@solvo.ru>,
   prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] atom_length/2 behavior
Date: Fri, 18 Jan 2002 12:07:27 +0100
X-Mailer: KMail [version 1.3.2]
References: <Pine.LNX.4.40.0201181318340.26685-100000@dual.solvo.ru>
In-Reply-To: <Pine.LNX.4.40.0201181318340.26685-100000@dual.solvo.ru>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

On Friday 18 January 2002 11:25, ??????? ?. ??????? wrote:
> ?- atom_length(1,A).
> A = 1
> Yes
> ?- atom_length([],A).
> A = 2
> Yes
> ?- atom_length([-],A).
> A = 1
> Yes
> ?- atom_length([-,2],A).
> A = 2
> Yes
>
> ?- atom_length([-,2,3],A).
> A = 3
> Yes
>
> ?- atom([-,2,3]).
> No
>
> %% Question : WHY ?

Atom length does a bit more than advertised, using the C function 
PL_get_nchars() with the flag CVT_ALL, which extracts a string
representation from atoms, packed strings, numbers (print-length)
as well as code and character-lists.

This explains many of them, but [-, 2] is not good as it is a
mix of one-character atoms and character codes.  I fixed 
PL_get_nchars() to reject mixed lists.  The patched version
is on the CVS server (pl-fli.c)

[] is dubious, but cannot be avoided.

If the flag iso is set, atom_length conforms to the ISO
standard, acception only atoms and packed strings (the
latter are not known in ISO and there is no ambiguity
interpreting the length of a packed character string).

I've also updated the manual on this predicate.

	Thanks --- Jan

