Subject: Re: [SWIPL] atom_length/2 behavior

From: Jan Wielemaker <[email-masked]>
Date: Fri, 18 Jan 2002 12:07:27 +0100

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