Basic predicates handling names of constants

Author(s): The CLIP Group.

The Ciao system provides builtin predicates which allow dealing with names of constants (atoms or numbers). Note that sometimes strings (character code lists) are more suitable to handle sequences of characters.

Usage and interface

Documentation on exports

PREDICATE
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.

(Trust) 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.

(Trust) 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.
General properties:

True:

  • The following properties hold globally:
    (basic_props:sideff/2)name(Const,String) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
ISOatom_codes(Atom,String)

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

(Trust) 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.

(Trust) 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.
General properties:

Test:atom_codes(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=aņo
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B=[97,241,111]
    then the following properties should hold globally:
    (native_props:not_fails/1)All the calls of the form atom_codes(A,B) do not fail.
    (native_props:is_det/1)All calls of the form atom_codes(A,B) are deterministic.

True:

  • The following properties hold globally:
    (basic_props:sideff/2)atom_codes(Atom,String) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.
    (native_props:is_det/1)All calls of the form atom_codes(Atom,String) are deterministic.

PREDICATE
ISOnumber_codes(Number,String)

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

(Trust) 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.

(Trust) 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.
General properties:

True:

  • The following properties hold globally:
    (basic_props:sideff/2)number_codes(Number,String) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

True: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:list/2)B is a list of num_codes.

PREDICATE
atom_number(Atom,Number)

Atom can be read as a representation of Number.

Usage 1:

  • Call and exit should be compatible with:
    (basic_props:num/1)Number is a number.
  • The following properties should hold at call time:
    (basic_props:atm/1)Atom is an atom.
  • The following properties should hold upon exit:
    (basic_props:num/1)Number is a number.
    (basic_props:atm/1)Atom is an atom.
    (basic_props:num/1)Number is a number.
  • The following properties should hold globally:
    (basic_props:eval/1)atom_number(Atom,Number) is evaluable at compile-time.

Usage 2:

  • The following properties should hold at call time:
    (term_typing:var/1)Atom is a free variable.
    (basic_props:num/1)Number is a number.
  • The following properties should hold upon exit:
    (basic_props:atm/1)Atom is an atom.
    (basic_props:atm/1)Atom is an atom.
    (basic_props:num/1)Number is a number.
  • The following properties should hold globally:
    (basic_props:eval/1)atom_number(Atom,Number) is evaluable at compile-time.
General properties:

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B=0.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=0.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=0.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B=0.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B= -0.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=-0.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=-0.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B0= -0.0
    (term_basic:= /2)term_basic:B=B0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B=1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B=1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B=0.Inf
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=0.Inf

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=0.Inf
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B=0.Inf

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B= -1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=-1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=-1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B= -1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B= -1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=-1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=-1.0
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B= -1.0

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B= -0.Inf
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=-0.Inf

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=-0.Inf
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B= -0.Inf

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B= -0.Inf
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=-0.Inf

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:B=0.Nan
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:A=0.Nan

Test:atom_number(A,B)

  • If the following properties should hold at call time:
    (term_basic:= /2)term_basic:A=0.Nan
    then the following properties should hold upon exit:
    (term_basic:= /2)term_basic:B=0.Nan

True:

  • The following properties hold globally:
    (basic_props:sideff/2)atom_number(Atom,Number) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.
    (native_props:is_det/1)All calls of the form atom_number(Atom,Number) are deterministic.

PREDICATE
atom_number(Atom,Base,Number)

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

Usage 1:

  • Call and exit should be compatible with:
    (basic_props:num/1)Base is a number.
  • The following properties should hold at call time:
    (basic_props:atm/1)Atom is an atom.
    (basic_props:num/1)Number is a number.
  • The following properties should hold upon exit:
    (basic_props:num/1)Base is a number.

Usage 2:

  • The following properties should hold at call time:
    (term_typing:var/1)Atom is a free variable.
    (basic_props:num/1)Base is a number.
    (basic_props:num/1)Number is a number.
  • The following properties should hold upon exit:
    (basic_props:atm/1)Atom is an atom.
General properties:

True:

  • The following properties hold globally:
    (basic_props:sideff/2)atom_number(Atom,Base,Number) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.
    (native_props:is_det/1)All calls of the form atom_number(Atom,Base,Number) are deterministic.

PREDICATE
ISOatom_length(Atom,Length)

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

(Trust) 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.
General properties:

True:

  • The following properties hold globally:
    (basic_props:sideff/2)atom_length(Atom,Length) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.
    (native_props:is_det/1)All calls of the form atom_length(Atom,Length) are deterministic.

PREDICATE
ISOatom_concat(Atom_1,Atom_2,Atom_12)

Atom_12 is the result of concatenating Atom_1 followed by Atom_2.

(Trust) Usage 1:

Concatenate two atoms.

  • Calls should, and exit will be compatible with:
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties should hold at call time:
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
  • The following properties hold upon exit:
    (basic_props:atm/1)Atom_12 is an atom.
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold globally:
    (basic_props:eval/1)atom_concat(Atom_1,Atom_2,Atom_12) is evaluable at compile-time.

(Trust) Usage 2:

Non-deterministically split an atom.

  • The following properties should hold at call time:
    (term_typing:var/1)Atom_1 is a free variable.
    (term_typing:var/1)Atom_2 is a free variable.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold upon exit:
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold globally:
    (basic_props:eval/1)atom_concat(Atom_1,Atom_2,Atom_12) is evaluable at compile-time.

(Trust) Usage 3:

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

  • The following properties should hold at call time:
    (term_typing:var/1)Atom_1 is a free variable.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold upon exit:
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold globally:
    (basic_props:eval/1)atom_concat(Atom_1,Atom_2,Atom_12) is evaluable at compile-time.

(Trust) Usage 4:

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

  • The following properties should hold at call time:
    (basic_props:atm/1)Atom_1 is an atom.
    (term_typing:var/1)Atom_2 is a free variable.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold upon exit:
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_1 is an atom.
    (basic_props:atm/1)Atom_2 is an atom.
    (basic_props:atm/1)Atom_12 is an atom.
  • The following properties hold globally:
    (basic_props:eval/1)atom_concat(Atom_1,Atom_2,Atom_12) is evaluable at compile-time.
General properties:

True:

  • The following properties hold globally:
    (basic_props:sideff/2)atom_concat(Atom_1,Atom_2,Atom_12) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.
    (native_props:is_det/1)All calls of the form atom_concat(Atom_1,Atom_2,Atom_12) are deterministic.

PREDICATE
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.

(Trust) Usage:

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

True:

  • The following properties hold globally:
    (basic_props:sideff/2)sub_atom(Atom,Before,Length,Sub_atom) is side-effect free.
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

REGTYPE

Usage:

Valid numeric base to convert numbers to strings or atoms

    Known bugs and planned improvements

    • Run-time checks have been reported not to work with this code. That means that either the assertions here, or the code that implements the run-time checks are erroneous.