This predicate doesn't appear to exist in v7.1.1. Some kind of comment needs to be put in the docs for predicates which have disappeared in the 6.6→7.1 changeover.
| Did you know ... | Search Documentation: |
| Predicate term_string/3 |
term_string(?Term,
?String, +Options)?- term_string(Term, 'a(A)', [variable_names(VNames)]). Term = a(_9674), VNames = ['A'=_9674].
This shows how to convert almost any "string" of 0s and 1s to an integer.
It takes advantage of the built-in term reading, thus avoiding an explicit loop and arithmetic.
binary_string_to_int(Str, Int) :-
( ( string(Str) ; atom(Str) )
-> atomics_to_string(["0b", Str], Literal)
; is_list(Str)
-> atomics_to_string(["0b"|Str], Literal)
; type_error(string_type, Str)
),
catch(term_string(Int, Literal, []),
error(syntax_error(_), _),
type_error(string_of_0s_and_1s, Str)).
?- binary_string_to_int('101', X).
X = 5.
?- binary_string_to_int([0, 0, 1, 0, 1], X).
X = 5.
?- binary_string_to_int(["1", "1", "0"], X).
X = 6.