11.3.121 name/2

Synopsis

name(+Constant, -Codes)

name(-Constant, +Codes)

Codes is the list consisting of the codes comprising the printed representation of Constant.

Arguments

Constant
atomic
Codes
codes

Description

Initially, either Constant must be instantiated to a number or an atom, or Codes must be instantiated to a proper codes.

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

If Constant is uninstantiated and Codes is initially instantiated to a codes 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.

There are atoms for which name(Const,CharList) is true, but which will not be constructed if name/2 is called with Const uninstantiated. One such atom is the atom '1976'. It is recommended that new programs use atom_codes/2 or number_codes/2, as these predicates do not have this inconsistency.

Exceptions

instantiation_error
If Constant and Codes are both uninstantiated
type_error
If Constant is not a constant
domain_error
Codes is not a codes

Examples

     | ?- 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

See Also

ref-lte-c2t.


Send feedback on this subject.