Re: atom_number/2: Type error
Carlo Capelli <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABty9wwjkKSCFvOWeEAhq-7NOQXXG+sTV2NGLYSP+Dy0NKea5w@mail.gmail.com> |
Hi Steve
are you sure it's not already a number ?
?- atom_number(1,X).
ERROR: atom_number/2: Type error: `atom' expected, found `1' (an integer)
?- atom_number('1',X).
X = 1.
Guard the conversion with a test before:
( atom(A) -> atom_number(A,N) ; N = A ),
2014-02-11 20:40 GMT+01:00 Steve Moyle <[email protected]>:
> I am struggling to understand this error message:
> ERROR: atom_number/2: Type error: `atom' expected, found `1'
>
> I am using Nico's prosqlite which seems to bring back items in single
> quotes.
> I have a table that comes from directly mapping sqlite3 'OTUTable'/6.
>
> So to change some of the fields I am using atom_number/2 to do some type
> conversion before any other operations.
>
> atom_number/2 seems to behave as I expect on the command line (e.g.):
>
> ?- findall(N, ('OTUTable'(A, B, C, D, E, F), atom_number(D, N)), Ns),
> sort(Ns, SNs).
> Ns = [1, 1, 1, 1, 1, 1, 1, 1, 1|...],
> SNs = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].
>
>
> But when it is used in the body of another predicate I get:
> ERROR: atom_number/2: Type error: `atom' expected, found `1'
>
> Is the `' wrapping the 1 giving more information that I cannot decode?
> :-)
>
> -- Steve
>
> BTW: I am using:
> Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.3.3-17-gf077dc2)
> on Ubuntu 12.04
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed