[ Term Manipulation | Reference Manual | Alphabetic Index ]
char_code(?Char, ?Code)
Succeeds if Code is the numeric character code of the character Char.
- Char
- One-character atom, string or variable.
- Code
- Integer or variable.
Description
If Char is instantiated to a one-character atom or string,
Code is unified with the corresponding numeric character code,
depending on the character encoding in use.
If Code is instantiated to an integer, Char is unified with the
corresponding one-character atom.
Modes and Determinism
- char_code(+, -) is det
- char_code(-, +) is det
Exceptions
- (5) type error
- Char is instantiated, but not to a 1-character string or atom.
- (5) type error
- Code is instantiated, but not to an integer.
- (6) out of range
- Code is instantiated to an integer outside the valid range for character codes.
- (4) instantiation fault
- Neither Char nor Code are instantiated (non-coroutine mode only).
Examples
Success:
char_code(b,98).
char_code("b",98).
char_code(C,99). (gives C=c).
char_code(a,I). (gives I=97).
Fail:
char_code(a,98).
Error:
char_code(C,I). (Error 4).
char_code(ab,I). (Error 5).
char_code(7,I). (Error 5).
char_code(C,-1). (Error 6).
See Also
get_char / 1, get_char / 2, put_char / 1, put_char / 2, string_code / 3, string_list / 2, string_list / 3