Jan Wielemaker wrote:
> On Friday 03 July 2009 02:24:57 pm Paulo Moura wrote:
>> On 2009/07/03, at 12:57, Tobias Kuhn wrote:
>>> I have a question concerning operators in SWI Prolog: I know that
>>> one can redefine the predefined operators, but can one also
>>> "undefine" them?
>>>
>>> Concretely, I would like to use the name "<" as a common predicate
>>> name "<(A,B)" that is not pretty-printed as "A<B".
>>>
>>> Using write_canonical/1 or using write_term/2 with the ignore_ops
>>> option does not really help because then also lists are written
>>> verbosely which is not what I want.
>>>
>>> Any ideas?
>> ?- current_op(P, T, <).
>> P = 700,
>> T = xfx ;
>> false.
>>
>> ?- op(0, xfx, <).
>> true.
>>
>> ?- write(<(a, b)).
>> <(a, b)
>> true.
Thank you all for your replies!
Actually, I should have read the manual more carefully where it cleary says "Precedence 0 removes
the declaration". Sorry.
> Note that there is a BIG price: If you try to load Prolog code after
> this declaration that happens to use X < Y, you'll get a syntax error.
Yes, this I encountered when trying it out. So I guess that retracting the operator "<" on a global
level is a very bad idea.
> Try to make these changes inside a module because operators are local to
> a module. Now you can use write_term(Term, [module(mymodule)]).
> Unfortunately though, this does not work at the moment because the
> system first looks for the operator locally and then globally. So, if
> you cancel it locally, it is still active :-(
>
> Another option is to use print/1 (or ~p in format) and a portray rule:
>
> portray(A<B) :-
> format('<(~w, ~w)', [A, B]).
>
> Of course, there is a moment where one starts wondering why one would
> like to use Prolog write -which writes Prolog terms- to emit something
> this weird?
It seems that the portray clause has to be defined in the module "user" and cannot be defined
locally in a user-defined module. Right?
Is there a simple way to print out operators in normal predicate form (as write_canonical/1 does)
but print out lists with the []-notation (as write/1 does)? This would solve my problem too.
Tobias
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog