name(+Constant, -Chars)

name(-Constant, +Chars)

Chars is the list consisting of the ASCII character codes comprising the printed representation of Constant.


Constant atomic

Chars chars


Initially, either Constant must be instantiated to a number or an atom, or Chars must be instantiated to a proper list of character codes (containing no variables).

If Constant is initially instantiated to an atom or number, Chars will be unified with the list of character codes that make up its printed representation.

If Constant is uninstantiated and Chars is initially instantiated to a list of characters that corresponds to the correct syntax of a number (either integer or float), Constant will be bound to that number; otherwise Constant will be instantiated to an atom containing exactly those characters.


     | ?- name(foo, L).
     L = [102,111,111]
     | ?- name('Foo', L).
     L = [70,111,111]
     | ?- name(431, L).
     L = [52,51,49]
     | ?- name(X, [102,111,111]).
     X = foo
     | ?- name(X, [52,51,49]).
     X = 431
     | ?- name(X, "15.0e+12").
     X = 1.5e+13

There are atoms that can be read and written by Prolog, and that can be converted to chars by name/2, but that it can not construct. One example of this is the atom 0:

     | ?- X = '0', atom(X), name(X, L).
     X = '0',
     L = [48]
     | ?- name(X, [48]), atom(X).
     | ?- name(X, [48]), integer(X).
     X = 0

This anomaly is present in DEC-10 Prolog and C-Prolog. name/2 is retained for compatibility with them. New programs should mainly use atom_chars/2 (see ref-lte-c2t) or number_chars/2 (see ref-lte-c2t) as appropriate.


If Constant and Chars are both uninstantiated
If Constant is not a constant
Chars is not a list of ASCII codes

See Also