From eb980421a9cd2a008b239ec673b45febd19d1fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Sun, 23 May 2010 18:39:46 +0100 Subject: [PATCH] make term_to_atom/2 a YAP builtin. --- docs/yap.tex | 9 +++++++++ library/dialect/swi.yap | 11 +---------- pl/utils.yap | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/yap.tex b/docs/yap.tex index b17128f02..0754c76c5 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -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 diff --git a/library/dialect/swi.yap b/library/dialect/swi.yap index dfe875bdf..76958105f 100755 --- a/library/dialect/swi.yap +++ b/library/dialect/swi.yap @@ -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), diff --git a/pl/utils.yap b/pl/utils.yap index 820387e31..f7bb1cc6c 100644 --- a/pl/utils.yap +++ b/pl/utils.yap @@ -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).