Subject: Re: write_term(Term, [variable_names(Vars)]) ?

From: Jan Wielemaker <[email-masked]>
Date: Tue, 29 Aug 2000 16:48:08 +0200

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