CHR + operator works imperfectly

View: New views
2 Messages — Rating Filter:   Alert me  

CHR + operator works imperfectly

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At first sight a CHR query involving the operator form of a constraint doesn't work at all.
However if we compile an auxiliary source re-defining the operator it works.

The following session demonstrates that.

leq.pl contains the standard example from the online doc plus operator definition added:
:- op( 500, xfx, leq).

1 ?- consult('leq.pl').
%  library(chr) compiled into chr 0.21 sec, 4,004,312 bytes
================================================================================
CHR compiler:
        The K.U.Leuven CHR System
                Contributors:   Tom Schrijvers, Jon Sneyers, Bart Demoen,
                                Jan Wielemaker
                Copyright:      K.U.Leuven, Belgium
                URL:            http://www.cs.kuleuven.be/~toms/CHR/
================================================================================
% leq.pl compiled into leq 0.22 sec, 4,047,568 bytes
true.

2 ?- a leq b, b leq c.
ERROR: Syntax error: Operator expected
ERROR: a
ERROR: ** here **
ERROR: leq b, b leq c .

2 ?- % however the non-operator query works:
|    leq(a,b), leq(b,c).
leq(a, c)
leq(b, c)
leq(a, b)
true .
leq(a, c)
leq(b, c)
leq(a, b)

3 ?- % now if we compile an auxiliary source re-defining the operator it works:
|    consult('leqop.pl').
% leqop.pl compiled 0.00 sec, 600 bytes
true.

4 ?- a leq b, b leq c.
a leq c
b leq c
a leq b
true .
a leq c
b leq c
a leq b

6 ?- halt.

$ cat leqop.pl
:- op( 500, xfx, leq).

$ cat leq.pl
:- module(leq,[leq/2]).
:- use_module(library(chr)).

:- chr_constraint leq/2.
:- op( 500, xfx, leq).

reflexivity  @ X leq Y <=> X=Y | true.
antisymmetry @ X leq Y , Y leq X <=> X=Y.
idempotence  @ X leq Y \ X leq Y <=> true.
transitivity @ X leq Y , Y leq Z ==> X leq Z.


--
Jean-Marc Vanel
http://jmvanel.free.fr/


Re: CHR + operator works imperfectly

by Tom Schrijvers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> At first sight a CHR query involving the operator form of a constraint
> doesn't work at all.

This is not a CHR issue, but an SWI-Prolog issue. You have to export the
operator declaration to make it available outside the module. Like so:

  :- module(leq,[leq/2, op( 500, xfx, leq)]). % op available outside module

  :- op( 500, xfx, leq). % op available inside module

Cheers,

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: tom.schrijvers@...
url: http://www.cs.kuleuven.be/~toms/

------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...
LightInTheBox - Buy quality products at wholesale price