Atom_number bug

I’m using: SWI-Prolog version 2.1.22

atom_number('1_2", X).

yields 12.

That is not a bug, it is a feature of integers. To make it easier to read long integer, e.g.


_ can be inserted instead of ‘,’ or ‘.’ depending upon how you are use to formatting integers, e.g.


As another example that might seem odd but is correct.

?- X = 1_234.
X = 1234.

See: Using digit groups in large integers

I got this error. The second query result is wrong:

SWI-Prolog (threaded, 64 bits, version 8.1.22)

?- atom_number('1r2', X).
X = 1r2.

?- atom_number(X, 1r2).
X = '12'.

but the right part should be 3 integers…

Pushed a fix.

1 Like