Re: writting anonymous variables in a file

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 02/03/2014 03:43 PM, db wrote:
> Hello,
>
> I want to write atoms with anonymous variables, like p(_, _), in a
> file, but in the file, each anonymous variable (_) have been
> replaced by a named anonymous variable, for example _906541.

SWI-Prolog's variables are written _GXXXX or _LXXXX.  Is this SWI-Prolog?

> Unfornatly, with big data, the same named anonymous variable appears
> more than once in the file.

This suggests you try to write a single non-ground term using
multiple calls to write, for example as below.

write('hello('), write(X), write(', '), write(Y), write(').\n').

This is not going to work.  There can be a garbage collection
between calls to write, which will cause the second write to
use different variable names.

This is no problem if all terms written are ground (then you
only have to worry about spaces and brackets if you use operator
instructions).  If your data is not-ground however, you must
either write it using a single call to write_term/3 or you must
call numbervars/3 on all combined data before writing it.

Numbervars/4 is the way out for writing anonymous variables as
_:

	numbervars(Term, 0, _, [singletons(true)]),
	write_term(Out, Term, [numbervars(true)]).

Hope this helps.  It is a topic which much misunderstanding.

	--- Jan



>
> How can I do write strictly anonymous variables ?
>
> Thanks a lot
>
> Dominique _______________________________________________ SWI-Prolog
> mailing list [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.