To solve this problem, you need a built-in predicate - if you do not list all the numbers explicitly (which is impractical, since there are infinitely many of them).
1
The easiest way:
maplist(number, L).
Or, recursively
allnumbers([]). allnumbers([N|Ns]) :- number(N), allnumbers(Ns).
2
In the commentary, you say that "meaning is given as an atom." This may mean that you get either [a, '1', '2'] or '[a, 1, 2] `. I guess the first one. And here you will need a built-in predicate to parse the name. Based on the errors of ISO-Prolog, we write:
numberatom(Atom) :- atom_chars(Atom, Chs), catch(number_chars(_, Chs), error(syntax_error(_),_), false).
Use numberatom/1 instead of number/1 , so write a recursion rule or use maplist/2
3
You might want to write a grammar instead of a catch... target. Recently there are many such definitions, you can look at this question .
4
If all the "value" is specified as an atom, you will need atom_chars/2 again, or you may need some specific solution, for example atom_to_term/3 , and then apply one of the above solutions.
false source share