sub_atom(?atom, ?integer_start, ?integer_length, ?integer_after, ?atom_sub) [ISO]

Enumeration of subatoms of an atom with their position and length. This predicate is re-executable as long as there are subatoms of the atom to enumerate.
The atom which is enumerated is the first parameter and the (generated) subatom is the last parameter. The second parameter is the start position of the subatom, the third parameter is the length of the subatom and the fourth parameter is the number of characters following the subatom:
    sub_atom(atom, Before, Length, After, Subatom).

The atom to enumerate must always be specified, if the remaining parameters are empty variables then all possible subatoms are generated.

see also: atom_base64/2 atom_codes/2 atom_compress/2 atom_concat/3 atom_encrypt/3 atom_final_md5/1 atom_integers/2 atom_length/2 atom_reset_md5/0 atom_update_md5/1 char_code/2 number_chars/2 number_codes/2 number_integers/2

Example
sub_atom(peter, B, L, A, S). the following solutions are generated:
B=0, L=0, A=5, S=
B=0, L=1, A=4, S=p
B=0, L=2, A=3, S=pe
B=0, L=3, A=2, S=pet
B=0, L=4, A=1, S=pete
B=0, L=5, A=0, S=peter
B=1, L=0, A=4, S=
B=1, L=1, A=3, S=e
B=1, L=2, A=2, S=et
B=1, L=3, A=1, S=ete
B=1, L=4, A=0, S=eter
B=2, L=0, A=3, S=
B=2, L=1, A=2, S=t
B=2, L=2, A=1, S=te
B=2, L=3, A=0, S=ter
B=3, L=0, A=2, S=
B=3, L=1, A=1, S=e
B=3, L=2, A=0, S=er
B=4, L=0, A=1, S=
B=4, L=1, A=0, S=r
B=5, L=0, A=0, S=
sub_atom(peter, B, 3, A, S). the following solutions are generated:
B=0, A=2, S=pet
B=1, A=1, S=ete
B=2, A=0, S=ter
sub_atom(peter, B, L, A, e). the following solutions are generated:
B=1, L=1, A=3
B=3, L=1, A=1

 

Exceptions  
Atom is a variable an instantiation_error exception is thrown
Atom is neither a variable nor an atom a type_error(atom, Atom) exception is thrown
Before is neither a variable nor an integer a type_error(integer, Before) exception is thrown
Before is an integer that is less than zero a domain_error(not_less_than_zero, Before) exception is thrown
Length is neither a variable nor an integer a type_error(integer, Length) exception is thrown
Length is an integer that is less than zero a domain_error(not_less_than_zero, Length) exception is thrown
After is neither a variable nor an integer a type_error(integer, After) exception is thrown
After is an integer that is less than zero a domain_error(not_less_than_zero, After) exception is thrown
Sub_atom is neither a variable nor an atom a type_error(atom, Sub_atom) exception is thrown

 

 

info@trinc-prolog.com