Conversion between constants and strings

Author(s): The Ciao Development Team.

The Ciao system provides builtin predicates which allow conversions between constants (atomic terms, i.e., atoms or numbers) and their string representation (character code lists). Note that sometimes strings are more suitable to handle sequences of characters.

Usage and interface

Documentation on exports

PREDICATEname/2
name(Const,String)

String is the list of the ASCII codes of the characters comprising the name of Const. Note that if Const is an atom whose name can be interpreted as a number (e.g. '96'), the predicate is not reversible, as that atom will not be constructed when Const is uninstantiated. Thus it is recommended that new programs use the ISO-compliant predicates atom_codes/2 or number_codes/2, as these predicates do not have this inconsistency.

Usage 1:

  • Calls should, and exit will be compatible with:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties should hold at call time:
    (basic_props:constant/1)Const is an atomic term (an atom or a number).
  • The following properties hold upon exit:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold globally:
    (basic_props:eval/1)name(Const,String) is evaluable at compile-time.

Usage 2:

If String can be interpreted as a number, Const is unified with that number, otherwise with the atom whose name is String.

  • The following properties should hold at call time:
    (term_typing:var/1)Const is a free variable.
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold upon exit:
    (basic_props:constant/1)Const is an atomic term (an atom or a number).
  • The following properties hold globally:
    (basic_props:eval/1)name(Const,String) is evaluable at compile-time.
Other properties:

PREDICATEatom_codes/2
ISOatom_codes(Atom,String)

String is the list of the ASCII codes of the characters comprising the name of Atom.

Usage 1:

  • Calls should, and exit will be compatible with:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties should hold at call time:
    (basic_props:atm/1)Atom is an atom.
  • The following properties hold upon exit:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold globally:
    (basic_props:eval/1)atom_codes(Atom,String) is evaluable at compile-time.

Usage 2:

  • Calls should, and exit will be compatible with:
    (basic_props:atm/1)Atom is an atom.
  • The following properties should hold at call time:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold upon exit:
    (basic_props:atm/1)Atom is an atom.
  • The following properties hold globally:
    (basic_props:eval/1)atom_codes(Atom,String) is evaluable at compile-time.
Other properties:

ISOnumber_codes(Number,String)

String is the list of the ASCII codes of the characters comprising a representation of Number.

Usage 1:

  • Calls should, and exit will be compatible with:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties should hold at call time:
    (basic_props:num/1)Number is a number.
  • The following properties hold upon exit:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold globally:
    (basic_props:eval/1)number_codes(Number,String) is evaluable at compile-time.

Usage 2:

  • The following properties should hold at call time:
    (term_typing:var/1)Number is a free variable.
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold upon exit:
    (basic_props:num/1)Number is a number.
  • The following properties hold globally:
    (basic_props:eval/1)number_codes(Number,String) is evaluable at compile-time.
Other properties:

number_codes(A,B)

  • If the following properties hold at call time:
    (basic_props:int/1)A is an integer.
    then the following properties hold upon exit:
    (basic_props:string/1)B is a string (a list of character codes).

number_codes(Number,Base,String)

String is the list of the ASCII codes of the characters comprising a representation of Number in base Base.

Usage 1:

  • Calls should, and exit will be compatible with:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties should hold at call time:
    (basic_props:num/1)Number is a number.
    (basic_props:int/1)Base is an integer.
  • The following properties hold upon exit:
    (basic_props:string/1)String is a string (a list of character codes).
  • The following properties hold globally:
    (basic_props:eval/1)number_codes(Number,Base,String) is evaluable at compile-time.

Usage 2:

Other properties:

PREDICATEatom_number/2
atom_number(Atom,Number)

Atom can be read as a representation of Number.

Usage 1:

Usage 2:

Other properties:

PREDICATEatom_number/3
atom_number(Atom,Base,Number)

Atom can be read as a representation of Number in base Base.

Usage 1:

Usage 2:

Other properties:

PREDICATEatom_length/2
ISOatom_length(Atom,Length)

Length is the number of characters forming the name of Atom.

Usage:

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Length is an integer.
  • The following properties should hold at call time:
    (basic_props:atm/1)Atom is an atom.
  • The following properties hold upon exit:
    (basic_props:int/1)Length is an integer.
  • The following properties hold globally:
    (basic_props:eval/1)atom_length(Atom,Length) is evaluable at compile-time.
Other properties:

PREDICATEatom_concat/3
ISOatom_concat(Atom_1,Atom_2,Atom_12)

Atom_12 is the result of concatenating Atom_1 followed by Atom_2.

Usage 1:

Concatenate two atoms.

Usage 2:

Non-deterministically split an atom.

Usage 3:

Take out of an atom a certain suffix (or fail if it cannot be done).

Usage 4:

Take out of an atom a certain prefix (or fail if it cannot be done).

Other properties:

PREDICATEsub_atom/4
sub_atom(Atom,Before,Length,Sub_atom)

Sub_atom is formed with Length consecutive characters of Atom after the Before character. For example, the goal sub_atom(summer,1,4,umme) succeeds.

Usage:

Other properties:

Documentation on imports

This module has the following direct dependencies: