These predicates enable atomic terms to be processed as a sequence of characters and character codes. Facilities exist to split and join atoms, to convert a single character to and from the corresponding character code, and to convert a number to and from a list of characters.
atom_length/2
atom_length(Atom, Length)
is true iff integer
Length
equals the number of characters of the name of the atom
Atom
.
Templates and modes for the predicate are as follows:
atom_length(+atom, ?integer)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
atom_length('scarlet', 5). | null | false |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
Goal | Theory | Variable | success(String goal,String theory,String variable) |
---|---|---|---|
atom_length('enchanted evening', N). | null | N | 17 |
atom_length('enchanted\evening', N). | null | N | 17 |
atom_length('', N). | null | N | 0 |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
atom_length(Atom, 4). | null | true | |
atom_length(1.23, 4). | null | true | |
atom_length(atom, '4'). | null | true |
atom_concat/3
atom_concat(Atom_1, Atom_2, Atom_12)
is true iff characters of the name of the atom
Atom_12
are the result of concatenating the characters of the name of the atom
Atom_2
to the characters of the name of the atom
Atom_1
.
atom_concat(Atom_1, Atom_2, Atom_12)
is re-executable.
Templates and modes for the predicate are as follows:
atom_concat(?atom, ?atom, +atom) atom_concat(+atom, +atom, -atom)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
atom_concat('hello', 'world', 'small world'). | null | false |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
atom_concat('small', T, 'smallworld'). | null | T | world | 10 | true |
atom_concat(T, 'world', 'smallworld'). | null | T | small | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | '' | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | hello | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | h | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | ello | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | he | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | llo | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | hel | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | lo | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | hell | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | o | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T1 | hello | 10 | true |
atom_concat(T1, T2, 'hello'). | null | T2 | '' | 10 | true |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
atom_concat(small, V2, V4). | null | true |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
sub_atom/5
sub_atom(Atom, Before, Length, After, Sub_atom)
is true iff atom
Atom
can be broken into three pieces,
AtomL
,
Sub_atom
and
AtomR
such that
Before
is the number of characters of the name of
AtomL
,
Length
is the number of characters of the name of
Sub_atom
and
After
is the number of characters of the name of
AtomR
.
Templates and modes for the predicate are as follows:
sub_atom(+atom, ?integer, ?integer, ?integer, ?atom)
sub_atom(Atom, Before, Length, After, Sub_atom)
is re-executable.
We run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
sub_atom(abracadabra, 0, 5, _, S2). | null | S2 | abrac | 10 | true |
sub_atom(abracadabra, _, 5, 0, S2). | null | S2 | dabra | 10 | true |
sub_atom(abracadabra, 3, L, 3, S2). | null | L | 5 | 10 | true |
sub_atom(abracadabra, 3, L, 3, S2). | null | S2 | acada | 10 | true |
sub_atom(abracadabra, B, 2, A, ab). | null | B | 0 | 10 | true |
sub_atom(abracadabra, B, 2, A, ab). | null | A | 9 | 10 | true |
sub_atom(abracadabra, B, 2, A, ab). | null | B | 7 | 10 | true |
sub_atom(abracadabra, B, 2, A, ab). | null | A | 2 | 10 | true |
sub_atom('Banana', 3, 2, _, S2). | null | S2 | an | 10 | true |
sub_atom('charity', _, 3, _, S2). | null | S2 | cha | 10 | true |
sub_atom('charity', _, 3, _, S2). | null | S2 | rit | 10 | true |
sub_atom('charity', _, 3, _, S2). | null | S2 | har | 10 | true |
sub_atom('charity', _, 3, _, S2). | null | S2 | ari | 10 | true |
sub_atom('charity', _, 3, _, S2). | null | S2 | ity | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 0 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 0 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 0 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 1 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 0 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 2 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 1 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 0 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 1 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 1 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Start | 2 | 10 | true |
sub_atom('ab', Start, Length, _, Sub_atom). | null | Length | 0 | 10 | true |
atom_chars/2
atom_chars(Atom, List)
is true iff
List
is a list whose elements are the one-char atoms whose names are the
successive characters of the name of atom
Atom
.
Templates and modes for the predicate are as follows:
atom_chars(+atom, ?character_list) atom_chars(-atom, +character_list)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
atom_chars('soap', ['s', 'o', 'p']). | null | false |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
atom_chars('', L). | null | L | [] | 10 | true |
atom_chars([], L). | null | L | ['[',']'] | 10 | true |
atom_chars('''', L). | null | L | ['''] | 10 | true |
atom_chars('ant', L). | null | L | [a,n,t] | 10 | true |
atom_chars(Str, ['s', 'o', 'p']). | null | Str | sop | 10 | true |
atom_chars('North', ['N' | X]). | null | X | [o,r,t,h] | 10 | true |
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
atom_chars(X, Y). | null | true |
atom_codes/2
atom_codes(Atom, List)
is true iff
List
is a list whose elements correspond to the successive characters of
the name
Atom
, and the value of each element is the character code for the
corresponding character of the name.
Templates and modes for the predicate are as follows:
atom_codes(+atom, ?character_code_list) atom_codes(-atom, +character_code_list)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
atom_codes('soap', [0's, 0'o, 0'p]). | null | false |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
atom_codes('', L). | null | L | [] | 10 | true |
atom_codes([], L). | null | L | [91,93] | 10 | true |
atom_codes('''', L). | null | L | [39] | 10 | true |
atom_codes('ant', L). | null | L | [97,110,116] | 10 | true |
atom_codes(Str, [0's, 0'o, 0'p]). | null | Str | sop | 10 | true |
atom_codes('North', [0'N | X]). | null | X | [111,114,116,104] | 10 | true |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
atom_codes(X, Y). | null | true |
char_code/2
char_code(Char, Code)
is true iff the character code for the one-char atom
Char
is
Code
.
Templates and modes for the predicate are as follows:
char_code(+character, ?character_code) char_code(-character, +character_code)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
char_code('b', 84). | null | false |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
char_code('a', Code). | null | Code | 97 | 10 | true |
char_code(Str, 99). | null | Str | c | 10 | true |
char_code(Str, 0'c). | null | Str | c | 10 | true |
char_code(Str, 163). | null | Str | '£' | 10 | true |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
char_code('ab', Int). | null | true | |
char_code(C, I). | null | true |
number_chars/2
number_chars(Number, List)
is true iff
List
is a list whose elements are the one-char atoms corresponding to a
character sequence of
Number
which could be output.
Templates and modes for the predicate are as follows:
number_chars(+number, ?character_list) number_chars(-number, +character_list)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
number_chars(33, ['3', '3']). | null | true |
number_chars(3.3, ['3', '.', '3']). | null | true |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
number_chars(33, L). | null | L | ['3','3'] | 10 | true |
number_chars(33.0, L). | null | L | ['3','3','.','0'] | 10 | true |
number_chars(X, ['3', '.', '3', 'E', '+', '0']). | null | X | 3.3 | 10 | true |
number_chars(A, ['-', '2', '5']). | null | A | -25 | 10 | true |
number_chars(A, ['\t','\n', ' ', '3']). | null | A | 3 | 10 | true |
number_chars(A, ['0', x, f]). | null | A | 15 | 10 | true |
number_chars(A, ['0', '''''', a]). | null | A | 97 | 10 | true |
number_chars(A, ['4', '.', '2']). | null | A | 4.2 | 10 | true |
number_chars(A, ['4', '2', '.', '0', 'e', '-', '1']). | null | A | 4.2 | 10 | true |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
number_chars(A, ['\t','3', 'g',' ']). | null | true | |
number_chars(A, ['\t','3', 'g','4']). | null | true | |
number_chars(A, ['\t','3', '4','g', '5']). | null | true | |
number_chars(A, ['\t', '3', '5', '-', '6']). | null | true |
number_codes/2
number_codes(Number, List)
is true iff
List
is a list whose elements are the character codes corresponding to a
character sequence of
Number
which could be output.
Templates and modes for the predicate are as follows:
number_codes(+number, ?character_code_list) number_codes(-number, +character_code_list)
Let's start with some simple tests verifying success or failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
number_codes(33, [0'3, 0'3]). | null | true |
number_codes(3.3, [0'3, 0'., 0'3]). | null | true |
Goal | Theory | Variable | Solution | Limit | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|---|
number_codes(33, L). | null | L | [51,51] | 10 | true |
number_codes(33.0, L). | null | L | [51,51,46,48] | 10 | true |
number_codes(A, [0'-, 0'2, 0'5]). | null | A | -25 | 10 | true |
number_codes(A, [0' , 0'3]). | null | A | 3 | 10 | true |
number_codes(A, [0'0, 0'x, 0'f]). | null | A | 15 | 10 | true |
number_codes(A, [0'4, 0'., 0'2]). | null | A | 4.2 | 10 | true |
number_codes(A, [0'4, 0'2, 0'., 0'0, 0'e, 0'-, 0'1]). | null | A | 4.2 | 10 | true |