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.
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.
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?
Cheers --- Jan
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog