add atom_to_term/3.

This commit is contained in:
Vitor Santos Costa 2010-01-26 12:19:13 +00:00
parent b0ea945ebc
commit 8ec6791183
2 changed files with 14 additions and 0 deletions

View File

@ -10550,6 +10550,13 @@ Convert the number @var{Number} to the string of character codes
Convert the atom @var{Number} to the difference list of character codes Convert the atom @var{Number} to the difference list of character codes
@var{Result-Result0}. @var{Result-Result0}.
@item atom_to_term(+@var{Atom}, -@var{Term}, -@var{Bindings})
@findex atom_to_term/3
@syindex atom_to_term/3
@cnindex atom_to_term/3
Use @var{Atom} as input to @code{read_term/2} using the option @code{variable_names} and return the read term in @var{Term} and the variable bindings in @var{Bindings}. @var{Bindings} is a list of @code{Name = Var} couples, thus providing access to the actual variable names. See also @code{read_term/2}. If Atom has no valid syntax, a syntax_error exception is raised.
@item read_from_chars(+@var{Chars}, -@var{Term}) @item read_from_chars(+@var{Chars}, -@var{Term})
@findex read_from_chars/2 @findex read_from_chars/2
@syindex read_from_chars/2 @syindex read_from_chars/2

View File

@ -538,6 +538,13 @@ sub_atom(At, Bef, Size, After, SubAt) :-
'$subtract_lists_of_variables'([V1|VL1],[V2|VL2],[V2|VL]) :- '$subtract_lists_of_variables'([V1|VL1],[V2|VL2],[V2|VL]) :-
'$subtract_lists_of_variables'([V1|VL1],VL2,VL). '$subtract_lists_of_variables'([V1|VL1],VL2,VL).
atom_to_term(Atom, Term, Bindings) :-
atom_codes(Atom, Chars),
charsio:open_mem_read_stream(Chars, Stream),
read_term(Stream, T, [variable_names(Bindings)]),
close(Stream),
T = Term.
simple(V) :- var(V), !. simple(V) :- var(V), !.
simple(A) :- atom(A), !. simple(A) :- atom(A), !.
simple(N) :- number(N). simple(N) :- number(N).