[eclipse-users] Problems with attributed variables

From: Matteo Monesi <matteo.monesi_at_gmail.com>
Date: Tue, 24 Jul 2007 10:57:39 +0200
Hi ECLiPSe users,

I'm trying to programming a bidimensional domain with attributed 
variables but I have a problem making unification predicates.

I modified the user manual example (with help):

        :-meta_attribute(dom,[unify:unify_dom/2]).

        unify_dom(_, Attr) :-
            /*** ANY + VAR ***/
            var(Attr).                  % Ignore if no attribute for 
this extension
        unify_dom(Term, Attr) :-
            compound(Attr),
            unify_term_dom(Term, Attr).

        unify_term_dom(Value, dom(ListY)) :-
            nonvar(Value),               % The attributed variable was 
instantiated
            /*** NONVAR + META ***/
            Value=dom(List),
            memberchk(List, ListY).
   
        %%%%%%%%%%%%%%
        %%% Modified Code %%%

        unify_term_dom(Y{dom:AttrY}, AttrX) :-
            -?->
            writeln(AttrY),
            unify_dom_dom(Y, AttrX, AttrY,AttrXY),
            setarg(1, AttrY, AttrXY).

        unify_dom_dom(_Y, AttrX,AttrY,AttrXY):-
            AttrX = dom(ListX),
            AttrY = dom(ListY),
            intersection(ListX,ListY,AttrXY).

        %%%%%%%%%%%%%%%

If I try in the goal:

    add_attribute(X,dom([1,2,3]),dom), add_attribute(Y,dom([1,2]),dom), X=Y.

it works, but if I try:

    test_dom(X,Y), X=Y.

with test_dom/2:

    test_dom(X,Y):-
        add_attribute(X,dom([1,2,3]),dom),
        add_attribute(Y,dom([1,2]),dom).

it gives me an error:

    trying to modify a read-only ground term in setarg(1, dom([1, 2, 
3]), [1, 2])

I obtained the same error here:

    test1(X,Y)

with

    test1(X,Y):-
                add_attribute(X,dom([(1,1), (2,1)]),dom),
                add_attribute(Y,dom([(2,1),(2,2)]),dom),
                X=Y.

I can't understand if it is a my mistake or an ECLiPSe bug.

Anyone can help me?

Thanks in advance for any hints,
Matteo
Received on Tue Jul 24 2007 - 09:58:07 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET