Reputation: 11
I know the Prolog-builtin "string_to_list". Now i need to reverse its functionality.
?- string_to_list('a*1+2', L).
L = [97, 42, 49, 43, 50].
How can i reverse this? Is there a builtin function? Anything that does what "desiredfunction" does, would be a great help.
?- desiredfunction([97, 42, 49, 43, 50], R).
R = 'a*1+2'.
Thank you.
Upvotes: 1
Views: 345
Reputation: 726499
string_to_list/2
is deprecated in favor of string_codes/2
.
The predicate is bidirectional, meaning that you can plug in a list, and get a string back on the other side.
string_codes(R, [97, 42, 49, 43, 50])
Better yet, use atom_codes/2
, which is also bidirectional, and is more widely supported among Prolog implementations:
atom_codes(R, [97, 42, 49, 43, 50])
a*1+2
Upvotes: 4