From jan@swi.psy.uva.nl  Tue Apr 25 22:29:52 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 WAA05933;
	Tue, 25 Apr 2000 22:29:51 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id WAA19507;
	Tue, 25 Apr 2000 22:29:51 +0200
Date: Tue, 25 Apr 2000 22:29:51 +0200
Message-Id: <200004252029.WAA19507@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: operators
To: "Bernd Fischer" <fisch@ptolemy.arc.nasa.gov>, <prolog@swi.psy.uva.nl>
In-Reply-To: Bernd Fischer's message of Tue, 25 Apr 2000 10:57:40 -0700
Phone: +31 - 20 - 525 6121

> 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

