Subject: Re: operators

From: Jan Wielemaker <[email-masked]>
Date: Tue, 25 Apr 2000 22:29:51 +0200

> Hi,
> 
> I try to abuse SWI-prolog as read-eval loop for a small language but can't
> wrestle it into using the operators I want. Specifically, I try to declare
> operators :/2 and |-/1 as infix and prefix with some suitable arity. The
> declarations
> 
> :- op(1150, fy, '|-').

| is a `solo' (punctuation) character and thus will never join in an
operator.  I think that has been in this group before.  Putting quotes
around an atom in an operator declaration makes no sense: operators
don't define what constitutes an atom.

> :- op(1100, xfx, ':').
> 
> go through, but don't work. ':' still refers to the module-operator, so
> x:t gives the message 'predicate x:t/0 not defined'; the directive
> 
> :- redefine_system_predicate ':'/2.
> 
> gives a syntax error. As for |-, it doesn't work either: |- 0 < 1 gives
> the warning 'Arithmetic: ``|'' is not a function' (instead of calling my
> prover to show me that 0 < 1 holds...)
> 
> Any easy ways out or am I stuffed? I don't really want to change my language
> syntax, though, and I certainly don't want to use quoted versions in the
> read-eval loop...

Syntax and semantics are seperate things.  :(Module, Goal) has defined
semantics for the compiler (meaning to call Goal in the context of
Module).  The operator definition says that Module:Goal is to be read
as :(Module, Goal).

It is highly undesirable to redefine system operators, as it will cause
normal Prolog source code to be read differently.

You cannot really redefine Module:Goal, as the toplevel query is handled
by call/1, which calls the compiler on non-trivial goals.  The compiler
translates Module:Goal to prove Goal in the context of Module.  If you
really insist, you can define query-expansion.

For short, user-defined operators should not conflict system operators
and stay away from the solo-punctutation characters {}[],|() (and a few
more, see the ISO standard, SWI-Prolog reference manual, etc.).

	Regards --- Jan