So as the title says - how do you convert a string into an integer? the idea is something like this:
convert(String,Integer).
examples:
convert('1',1).
convert('33',33).
I'm using swi prolog
So as the title says - how do you convert a string into an integer? the idea is something like this:
convert(String,Integer).
examples:
convert('1',1).
convert('33',33).
I'm using swi prolog
Assuming you really meant a string and not an atom, use number_codes
.
?- number_codes(11, "11").
true.
?- number_codes(11, Str).
Str = [49, 49]. % ASCII/UTF-8
?- number_codes(N, "11").
N = 11.
Perhaps use of atom_codes(?Atom, ?String)
and number_chars(?Number, ?CharList)
would do it.
A simple example using Visual Prolog 10
==============================
% UNS-EPISI-LAB-IA
implement main
open core
clauses
run() :-
console::write("Valor de A? "),
A = console::readLine(),
console::write("Valor de B? "),
B = console::readLine(),
Areal = toTerm(real, A),
Breal = toTerm(real, B),
console::write("A + B = ", Areal + Breal),
_ = console::readChar().
end implement main
goal
console::runUtf8(main::run).