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 04:38 PM, db wrote:
>
> Hi Jan,
>
> Le 03/02/2014 16:00, Jan Wielemaker a �crit :
>> 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?
>
> I gave a bad example. The true message is :
>
> "Singleton-marked variable appears more than once: _G506341"
>
>
>> 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').
>
> That is what I have done, because I needed to format
> my list.
> More precisely, I wrote the term
> p(_X, _Y)
> and further (with numerous writings between them)
> the term
> p(_Z, _T).
>
> But _X and _Y have been replaced in my destination file
> by the same variable _G506341.

Yes, that can happed. Similarly, writing p(_X, _Y) and later p(_X, _Z)
might cause the _X not to be the same. It just can't work for non-ground
terms. Using numbervars or some other way to name the variables is the
only thing that can work. The _GXXXX names are simple not stable and,
AFAIK, that is the case in all Prolog system I know about that have a
garbage collector.

Note that numbervars binds your variables, so you typically do

	\+ \+ ( numbervars(Term, 0, _, [singletons(true)]),
		<do the actual writing>
	      ).

	Cheers --- Jan
_______________________________________________
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.