make term_to_atom/2 a YAP builtin.

This commit is contained in:
Vítor Santos Costa 2010-05-23 18:39:46 +01:00
parent 79649439ee
commit eb980421a9
3 changed files with 18 additions and 10 deletions

View File

@ -10886,6 +10886,15 @@ Convert the atom @var{Number} to the difference list of character codes
@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 term_to_atom(?@var{Term}, ?@var{Atom})
@findex term_to_atom/2
@syindex term_to_atom/2
@cnindex term_to_atom/2
True if @var{Atom} describes a term that unifies with @var{Term}. When
@var{Atom} is instantiated @var{Atom} is converted and then unified with
@var{Term}. If @var{Atom} has no valid syntax, a syntax_error exception
is raised. Otherwise @var{Term} is ``written'' on @var{Atom} using
@code{write_term/2} with the option quoted(true).
@item read_from_chars(+@var{Chars}, -@var{Term})
@findex read_from_chars/2

View File

@ -3,8 +3,7 @@
% written in an on-demand basis.
:- module(system, [term_to_atom/2,
concat_atom/2,
:- module(system, [concat_atom/2,
concat_atom/3,
setenv/2,
prolog_to_os_filename/2,
@ -260,14 +259,6 @@ use_foreign_library(A) :-
load_foreign_library(A),
assert(loaded(foreign_library(A))).
term_to_atom(Term,Atom) :-
nonvar(Atom), !,
atom_codes(Atom,S),
read_from_chars(S,Term).
term_to_atom(Term,Atom) :-
write_to_chars(Term,S),
atom_codes(Atom,S).
concat_atom([A|List], Separator, New) :- var(List), !,
atom_codes(Separator,[C]),
atom_codes(New, NewChars),

View File

@ -553,6 +553,14 @@ atom_to_term(Atom, Term, Bindings) :-
close(Stream),
T = Term.
term_to_atom(Term,Atom) :-
nonvar(Atom), !,
atom_codes(Atom,S),
read_from_chars(S,Term).
term_to_atom(Term,Atom) :-
write_to_chars(Term,S),
atom_codes(Atom,S).
simple(V) :- var(V), !.
simple(A) :- atom(A), !.
simple(N) :- number(N).