[ Strings and Atoms | Reference Manual | Alphabetic Index ]

string_list(?String, ?List)

List is a list whose elements are the integer codes of the bytes in the string
String
String or variable.
List
List of integers (in the range 0 to 255) and/or variables, or simply a variable.

Description

This predicate performs conversion between a byte string and the corresponding list of integers in the range 0..255.

If String is instantiated, unifies List with the list whose elements are the integer codes for the bytes in the string.

If List is instantiated, unifies String with the string composed from the bytes given by the list elements in range 0..255.

Modes and Determinism

Exceptions

(5) type error
String is neither a string nor a variable.
(5) type error
List is neither a list nor a variable.
(6) out of range
One (or more) elements of List are not integers in the range 0 to 255.
(4) instantiation fault
Neither String or List are ground (non-coroutine mode only).

Examples

   Success:
   string_list(S,[65,98,99]).          (gives S="Abc").
   string_list("abc",L).               (gives L=[97,98,99]).
   string_list("abc",[97,A,99]).       (gives A=98).
   string_list(S,[127]).               (gives S="\177").
   string_list("abc",[97|A]).          (gives A=[98,99]).
   Fail:
   string_list("abc",[98,99,100]).
   Error:
   string_list(S,[A|[128]]).           (Error 4).
   string_list(S,[1|A]).               (Error 4).
   string_list('string',L).            (Error 5).
   string_list(S,"list").              (Error 5).
   string_list('string',[128]).        (Error 5).
   string_list(S,["B"]).               (Error 5).
   string_list(S,[256]).               (Error 6).



See Also

string_list / 3, string_codes / 2, string_chars / 2