Re: != as an operator

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Tue 24 Aug 2004 01:44:40 PM GMT
Message-ID: <412B4648.8040905@icparc.ic.ac.uk>
geoff@cs.miami.edu wrote:
> Hi,
> 
> I would like to have != as an infix operator, but ...
> 
>     ECLiPSe Constraint Logic Programming System [kernel]
>     Copyright Imperial College London and ICL
>     Certain libraries copyright Parc Technologies Ltd
>     GMP library copyright Free Software Foundation
>     Version 5.2 #10, Tue Jun 26 02:14 2001
>     [eclipse 1]: op(10,xfx,'!=').
> 
>     Yes (0.00s cpu)
>     [eclipse 2]: read(X),display(X),nl.
>      a != b.
>     syntax error: postfix/infix operator expected
>     | a != b.
>     |   ^ here
> 
>     No (0.00s cpu)
> 
> I do not want to quote the operator. Does anyone know how to do this? I 
> guess the ! is being read as a cut?

The ECLiPSe lexical analyzer treats sequences of 'symbols' (e.g. =:= )
as a single token.  However, the ! is not classified as a normal 'symbol'
but as 'special' and therefore always treated as a separate token, even if
followed by a 'symbol', as in your case.

You can change the "character class" of the exclamation mark to 'symbol'
with the following declaration:

:- local chtab(0'!, symbol).

Then your above example will work as expected. But be careful: some of your
old code might break, in particular things like

p :- q, !.

will no longer work because '!.' will now be parsed as a single atom rather
than as ! followed by fullstop. You can work around this by inserting a space:

p :- q, ! .

Fortunately, the effect of the chtab-declaration is local to the module where
you issue the declaration, so, depending on the application you have in mind,
the funny side effects may be acceptable or not...


-- 
  Joachim Schimpf              /             phone: +44 20 7594 8187
  IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
  Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Tue Aug 24 14:45:55 2004

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:30 PM GMT GMT