[eclipse-clp-users] Attributed variables unification failure within a conditional construct

From: Chris Meudec <Chris.Meudec_at_...438...>
Date: Tue, 30 Jul 2024 14:24:52 +0000
Hi all,
I am getting reacquainted with ECLiPSe Prolog after some time with Sicstus, so it appears I am rusty.

I have used attributed variables extensively in the past, but I am stuck.
I have defined an attributed variable and have defined a unification handler, but whenever my unification handler fails (as it should)  as part of a condition in a condition construct (+Condition -> +Then ; +Else) the entire construct fails rather than executing the Else part.

I have condensed the problem to a short example below.

:- module('try').
:- meta_attribute('try', [unify:unify_name/2]).

unify_name(_, Attr) :-
    var(Attr).
unify_name(Term, Attr) :-
    compound(Attr),
    unify_term_name(Term, Attr).

unify_term_name(_{AttrY}, AttrX) :-
    -?->
    AttrX = AttrY.

try :-
    add_attribute(X, try('X')),
    Declarator = X,
    (Declarator = 2 ->        %when unification fails here as it should, the else part is not executed as expected
        printf("hello there 10", [])
    ;
        printf("hello there 20", [])
    ).
try :-
printf("hello there 30", []).

I get 30 printed out but I was expecting 20.

Why? It is rather odd.

With this attribute, I only want it to succeed when unified with a free variable.

I could avoid using the conditional construct in such cases but it does not help my understanding and the current behaviour is a little surprising to me.

Thanks,
Chris
--
Dr Chris Meudec<http://www.echancrure.eu/> (he/him) Maitrise, PhD, MA (T&L)
Lecturer in Software Development
South East Technological University - Carlow Campus - Ireland
E chris.meudec_at_...438...<mailto:chris.meudec_at_...438...> |  setu.ie<https://setu.ie/>
[turn on images]<https://setu.ie/>

Kilkenny Road Campus, Kilkenny Road, Carlow, R93 V960, Ireland
Campas Bhóthar Chill Chainnigh, Bóthar Chill Chainnigh, Ceatharlach, R93 V960, Éire
Received on Tue Jul 30 2024 - 14:58:59 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:21 CEST