<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> <TITLE> Variable naming/numbering </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual027.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual029.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> <HR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE> <TR><TD><FONT SIZE=4><B><A NAME="htoc82">7.5</A></B></FONT></TD> <TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Variable naming/numbering</B></FONT></TD> </TR></TABLE></DIV></TD> </TR></TABLE><UL> <LI><A HREF="manual028.html#toc56"> <TT>name_singleton_vars/1</TT></A> <LI><A HREF="manual028.html#toc57"> <TT>name_query_vars/2</TT></A> <LI><A HREF="manual028.html#toc58"> <TT>bind_variables/2</TT>, <TT>numbervars/3</TT>, <TT>numbervars/1</TT></A> <LI><A HREF="manual028.html#toc59"> <TT>term_ref/2</TT></A> </UL> <A NAME="Variable-naming/numbering"></A><BR> <A NAME="toc56"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc83">7.5.1</A></B></TD> <TD WIDTH="100%" ALIGN=center><TT><B>name_singleton_vars/1</B></TT></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="name-singleton-vars/1"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> name_singleton_vars(?term)</TT></DL> <B>Description</B><BR> <BR> <TT>name_singleton_vars(Term)</TT> binds each singleton variable appearing in <TT>Term</TT> with a term of the form <TT>'$VARNAME'('_')</TT>. Such a term can be output by <TT>write_term/3</TT> as a variable name (section <A HREF="manual037.html#write-term/3">7.14.6</A>).<BR> <BR> <B>Errors</B><BR> <BR> None.<BR> <BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc57"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc84">7.5.2</A></B></TD> <TD WIDTH="100%" ALIGN=center><TT><B>name_query_vars/2</B></TT></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="name-query-vars/2"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> name_query_vars(+list, ?list)</TT></DL> <B>Description</B><BR> <BR> <TT>name_query_vars(List, Rest)</TT> for each element of <TT>List</TT> of the form <TT>Name = Var</TT> where <TT>Name</TT> is an atom and <TT>Var</TT> a variable, binds <TT>Var</TT> with the term <TT>'$VARNAME'(Name)</TT>. Such a term can be output by <TT>write_term/3</TT> as a variable name (section <A HREF="manual037.html#write-term/3">7.14.6</A>). <TT>Rest</TT> is unified with the list of elements of <TT>List</TT> that have not given rise to a binding. This predicate is provided as a way to name the variable lists obtained returned by <TT>read_term/3</TT> with <TT>variable_names(List)</TT> or <TT>singletons(List)</TT> options (section <A HREF="manual037.html#read-term/3">7.14.1</A>).<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is a partial list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, List)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Rest</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Rest)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicate.<BR> <BR> <A NAME="toc58"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc85">7.5.3</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>bind_variables/2</TT>, <TT>numbervars/3</TT>, <TT>numbervars/1</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="bind-variables/2"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> bind_variables(?term, +var_binding_option_list)<BR> numbervars(?term, +integer, ?integer)<BR> numbervars(?term)</TT></DL> <B>Description</B><BR> <BR> <TT>bind_variables(Term, Options)</TT> binds each variable appearing in <TT>Term</TT> according to the options given by <TT>Options</TT>. <BR> <BR> <B>Variable binding options</B>: <TT>Options</TT> is a list of variable binding options. If this list contains contradictory options, the rightmost option is the one which applies. Possible options are: <UL><LI><TT>numbervars</TT>: specifies that each variable appearing in <TT>Term</TT> should be bound to a term of the form <TT>'$VAR'(N)</TT> where <TT>N</TT> is an integer. Such a term can be output by <TT>write_term/3</TT> as a variable name (section <A HREF="manual037.html#write-term/3">7.14.6</A>). This is the default.<BR> <BR> <LI><TT>namevars</TT>: specifies that each variables appearing in <TT>Term</TT> shall be bound to a term of the form <TT>'$VARNAME'(Name)</TT> where <TT>Name</TT> is the atom that would be output by <TT>write_term/3</TT> seeing a term of the <TT>'$VAR'(N)</TT> where <TT>N</TT> is an integer. Such a term can be output by <TT>write_term/3</TT> as a variable name (section <A HREF="manual037.html#write-term/3">7.14.6</A>). This is the alternative to <TT>numbervars</TT>.<BR> <BR> <LI><TT>from(From)</TT>: the first integer <TT>N</TT> to use for number/name variables of <TT>Term</TT> is <TT>From</TT>. The default value is <TT>0</TT>.<BR> <BR> <LI><TT>next(Next)</TT>: when <TT>bind_variables/2</TT> succeeds, <TT>Next</TT> is unified with the (last integer <TT>N</TT>)+1 used to bind the variables of <TT>Term</TT>. <BR> <BR> <LI><TT>exclude(List)</TT>: collects all variable names appearing in <TT>List</TT> to avoid a clash when binding a variable of <TT>Term</TT>. Precisely a number <TT>N</TT> >= <TT>From</TT> will not be used to bind a variable of <TT>Term</TT> if: <UL><LI>there is a sub-term of <TT>List</TT> of the form <TT>'$VAR'(N)</TT> or <TT>'$VARNAME'(Name)</TT> where <TT>Name</TT> is the constant that would be output by <TT>write_term/3</TT> seeing a term of the <TT>'$VAR'(N)</TT>.<BR> <BR> <LI>an element of <TT>List</TT> is of the form <TT>Name = Var</TT> where <TT>Name</TT> is an atom that would be output by <TT>write_term/3</TT> on seeing a term of the from <TT>'$VAR'(N)</TT>. This case allows for lists returned by <TT>read_term/3</TT> (with <TT>variable_names(List)</TT> or <TT>singletons(List)</TT> options) (section <A HREF="manual037.html#read-term/3">7.14.1</A>) and by <TT>name_query_vars/2</TT> (section <A HREF="#name-query-vars/2">7.5.2</A>).</UL></UL> <TT>numbervars(Term, From, Next)</TT> is equivalent to <TT>bind_variables(Term, [from(From), next(Next)]</TT>, i.e. each variable of <TT>Term</TT> is bound to <TT>'$VAR'(N)</TT> where <TT>From <=</TT> <TT>N</TT> < <TT>Next</TT>.<BR> <BR> <TT>numbervars(Term)</TT> is equivalent to <TT>numbervars(Term, 0, _)</TT>.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Options</TT> is a partial list or a list with an element <TT>E</TT> which is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Options</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Options)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>Options</TT> list is neither a variable nor a variable binding option</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(var_binding_option, E)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>From</TT> is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>From</TT> is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, From)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Next</TT> is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, Next)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is a partial list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, List)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc59"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc86">7.5.4</A></B></TD> <TD WIDTH="100%" ALIGN=center><TT><B>term_ref/2</B></TT></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> term_ref(+term, ?integer)<BR> term_ref(?term, +integer)</TT></DL> <B>Description</B><BR> <BR> <TT>term_ref(Term, Ref)</TT> succeeds if the internal reference of <TT>Term</TT> is <TT>Ref</TT>. This predicate can be used either to obtain the internal reference of a term or to obtain the term associated to a given reference. Note that two identical terms can have different internal references. A good way to use this predicate is to first record the internal reference of a given term and to later re-obtain the term via this reference.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Term</TT> and <TT>Ref</TT> are both variables</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Ref</TT> is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, Ref)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Ref</TT> is an integer < 0</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(not_less_than_zero, Ref)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicate.<BR> <BR> <HR SIZE=2> Copyright (C) 1999-2002 Daniel Diaz <BR> <BR> Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. <BR> <BR> <A HREF="index.html#copyright">More about the copyright</A> <HR> <A HREF="manual027.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual029.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>