From jan@swi.psy.uva.nl  Tue Aug 29 16:53:47 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA16558;
	Tue, 29 Aug 2000 16:53:47 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA17142;
	Tue, 29 Aug 2000 16:53:51 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Lourens van der Meij <lourens@cs.vu.nl>, prolog@swi.psy.uva.nl
Subject: Re: write_term(Term, [variable_names(Vars)]) ?
Date: Tue, 29 Aug 2000 16:48:08 +0200
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
References: <Pine.GSO.4.21.0008291527430.10108-100000@fluit.cs.vu.nl>
In-Reply-To: <Pine.GSO.4.21.0008291527430.10108-100000@fluit.cs.vu.nl>
MIME-Version: 1.0
Message-Id: <00082916535005.13688@gollem>
Content-Transfer-Encoding: 8bit

On Tue, 29 Aug 2000, Lourens van der Meij wrote:
>I could not find a write predicate in SWI-Prolog that writes terms such
>that a variable Var occurring in the term is replaced by Name if there is
>an entry Name = Var in a supplied Vars list,  complementary to
>read_term(Term,[variable_names(Vars)]).
> 
>Is there such a write predicate or write option in SWI-Prolog?
>
>If not, I suppose I could use write_term by first binding all variables in
>a 'Name=Var'-list:
>
>1)	Var = '$NAME'(Name) for each entry Name = Var in'Name=Var'-list 
>
>2) 	define a portray hook for'$NAME'(Name) 
>		user:portray($NAME'(Name)) :- 
>			write_term(Name, [quoted(false)]).
>3)	use write_term with portray(true)?
>
>However I don't find this an elegant solutionn.

Not really, but it would work.  Older versions actually used about this
technique for the current numbervars option.

>Jan, if there is no such write predicate in SWI-prolog yet, is it possible
>to add such a complementary variable_names/1 option to the write_term/[2,3] 
>predicate?

For now, I would suggest a little hack using the above technique (it is
only a few lines).  But I'll consider the proposed interface.  It looks
nice and complementary to read_term/3.

>A minor remark on write_term in SWI-Prolog:
>
>?- write_term(aap(P,Q,f(P)),[variable_names(['P'=P,'Q'=Q]),noot]).
>aap(_G510, _G513, f(_G510))
>
>P = _G510
>Q = _G513 
>
>There is no error message for an undefined option in
>write_term[2,3] in SWI-Prolog(3.3.9).

All the predicates accepting option-lists silently ignore
unknown options.  If you set the flag `iso' to true, it will
report a domain-error.

	Regards --- Jan

