Re: [eclipse-users] Problems with attributed variables

From: Kish Shen <kisshen_at_...5...>
Date: Tue, 24 Jul 2007 16:40:25 +0100
Hi Matteo.

Matteo Monesi wrote:
> 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).
>
>   
Just an aside: the name AttrXY was somewhat confusing to me -- DomXY may 
be a better name for the variable, as it is the list of domain, rather 
than the whole attribute structure (i.e. dom/1).

>         %%%%%%%%%%%%%%%
>
> 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])
>
>   
The reason you get this error is because the term dom([1,2,3]) appears 
explicitly in your code, and
is thus compiled and store (in the compiled form) by ECLiPSe. When the 
code is ran, the compiled form
of this is used (instead of being constructed at runtime), and thus you 
cannot modify it.

Remember that setarg/3 is quite low-level, and its exact behaviour is 
dependnet on such implementation issues as the above.

This should normally not be a problem because in normal use, you 
probably would not have something like dom([1,2,3]) in your code -- you 
will have a predicate that will add the domain, like:

add_dom(X, Dom) :-
    add_attribute(X, dom(Dom), dom).

> 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
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users@...2...
> http://www.crosscoreop.com/mailman/options/eclipse-users
>   
Received on Tue Jul 24 2007 - 16:40:42 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST