Search code examples
castingprologiso-prolog

SICStus Prolog atom to string


I need to convert a Prolog atom to an integer. For example:

?- convert('123', X).
X = 123
yes

I have seen some SO answers about that, but they rely on SWI-Prolog, and I am forced to use SICStus Prolog. Casting to string will also do the job, as I am aware of the number_codes/2 predicate.

Thanks for your help.


Solution

  • Ok, I found an answer (in case you too need it):

    atom_chars('123', Y), number_chars(X, Y).