[ Strings and Atoms | Reference Manual | Alphabetic Index ]
integer_atom(?Integer, ?Atom)
Conversion between an integer and an atom.
It is more efficient to use number_string/2 wherever possible.
- Integer
- Integer or variable.
- Atom
- Atom or variable.
Description
If Integer is instantiated, converts it to its associated atomic
representation Atom.
If Atom is instantiated, converts it to its integer form Integer.
Atom may contain only digits possibly preceded by a + or a -.
Modes and Determinism
- integer_atom(+, -) is det
- integer_atom(-, +) is semidet
Fail Conditions
Fails if Atom does not represent an integer
Exceptions
- (5) type error
- Integer is instantiated, but not to an integer.
- (5) type error
- Atom is instantiated, but not to an atom.
- (4) instantiation fault
- Both arguments are free variables (non-coroutine mode only).
Examples
Success:
integer_atom(1989,X). (gives X = '1989').
integer_atom(X,'+12'). (gives X = 12).
integer_atom(-7,X). (gives X = '-7').
integer_atom(X,'-7'). (gives X = -7).
integer_atom(N,'1234'). (gives N = 1234).
Fail:
integer_atom(I,'- 15').
integer_atom(I,' +15').
integer_atom(I,'2 ').
integer_atom(1234,'Abcd').
integer_atom(222,'123').
integer_atom(x,'+12').
Error:
integer_atom(A,B). (Error 4).
integer_atom(124.5,X). (Error 5).
integer_atom(N,1234). (Error 5).
See Also
integer / 1, atom / 1, number_string / 2, sprintf / 3