projog

3.54. atom_chars / atom_codes / number_chars / number_codes

Examples

?- atom_chars(X,[a,p,p,l,e]).
X = apple

yes

?- atom_chars(X,[97,112,112,108,101]).
X = apple

yes

?- atom_chars(apple,X).
X = [a,p,p,l,e]

yes

?- atom_chars(apple,[a,p,p,l,e]).

yes

?- atom_chars(apple,[97,112,112,108,101]).

no

?- atom_chars('APPLE',['A','P','P','L','E']).

yes

?- atom_chars(apple,[a,112,p,108,101]).

no

?- atom_chars(apple,[a,p,l,l,e]).

no

?- atom_chars(apple,[a,p,p,l,e,s]).

no

?- atom_chars(apple,[a,112,p,108,102]).

no

?- atom_chars('APPLE',[a,p,p,l,e]).

no

?- atom_chars('apple',['A','P','P','L','E']).

no

?- atom_chars(apple,[X,Y,Y,Z,e]).
X = a
Y = p
Z = l

yes

?- atom_chars(apple,[X,Y,Z,Z,e]).

no

?- atom_chars(X,'apple').

As the first argument: X is a variable the second argument needs to be a list but was: apple of type: ATOM

?- atom_codes(X,[a,p,p,l,e]).
X = apple

yes

?- atom_codes(X,[97,112,112,108,101]).
X = apple

yes

?- atom_codes(apple,[a,p,p,l,e]).

no

?- atom_codes(apple,[97,112,112,108,101]).

yes

?- atom_codes(apple,X).
X = [97,112,112,108,101]

yes

?- atom_codes('APPLE',[65,80,80,76,69]).

yes

?- atom_codes(apple,[a,112,p,108,101]).

no

?- atom_codes(apple,[97,112,108,108,101]).

no

?- atom_codes(apple,[97,112,112,108,101,102]).

no

?- atom_codes(apple,[a,112,p,108,102]).

no

?- atom_codes('APPLE',[97,112,112,108,101]).

no

?- atom_codes('apple',[65,80,80,76,69]).

no

?- atom_codes(apple,[X,Y,Y,Z,101]).
X = 97
Y = 112
Z = 108

yes

?- atom_codes(apple,[X,Y,Z,Z,101]).

no

?- atom_codes(X,'apple').

As the first argument: X is a variable the second argument needs to be a list but was: apple of type: ATOM

?- number_chars(-193457260, ['-', '1','9','3','4','5','7','2','6','0']).

yes

?- number_chars(-193457260, [45,49,57,51,52,53,55,50,54,48]).

no

?- number_chars(193457260,X).
X = [1,9,3,4,5,7,2,6,0]

yes

?- number_chars(-193457260,X).
X = [-,1,9,3,4,5,7,2,6,0]

yes

?- number_chars(X,['1','9','3','4','5','7','2','6','0']).
X = 193457260

yes

?- number_chars(X,['-', '1','9','3','4','5','7','2','6','0']).
X = -193457260

yes

?- number_chars(X,['o','n','e']).

Could not convert characters to an integer: 'one'

?- number_chars(X,1257).

As the first argument: X is a variable the second argument needs to be a list but was: 1257 of type: INTEGER

?- number_chars(X,['6','.','4']).
X = 6.4

yes

?- number_chars(X,['-','7','2','.','4','6','3']).
X = -72.463

yes

?- number_chars(X,['.','4','6','3']).
X = 0.463

yes

?- number_chars(X,['-','.','4','6','3']).
X = -0.463

yes

?- number_chars('193457260',X).

Unexpected type for first argument: ATOM

?- number_codes(-193457260, [45,49,57,51,52,53,55,50,54,48]).

yes

?- number_codes(-193457260, ['-','1','9','3','4','5','7','2','6','0']).

no

?- number_codes(193457260,X).
X = [49,57,51,52,53,55,50,54,48]

yes

?- number_codes(-193457260,X).
X = [45,49,57,51,52,53,55,50,54,48]

yes

?- number_codes(X,[49,57,51,52,53,55,50,54,48]).
X = 193457260

yes

?- number_codes(X,[45,49,57,51,52,53,55,50,54,48]).
X = -193457260

yes

?- number_codes(X,['o','n','e']).

Could not convert characters to an integer: 'one'

?- number_codes(X,1257).

As the first argument: X is a variable the second argument needs to be a list but was: 1257 of type: INTEGER

?- number_codes(X,[54,46,52]).
X = 6.4

yes

?- number_codes(X,[45,55,50,46,52,54,51]).
X = -72.463

yes

?- number_codes(X,[46,52,54,51]).
X = 0.463

yes

?- number_codes(X,[45,46,52,54,51]).
X = -0.463

yes

?- number_codes('193457260',X).

Unexpected type for first argument: ATOM