Attempting to tet for the consistency of an unbound variable again.

From: Dirk Mittler (mdirk_at_sympatico.ca)
Date: 08/24/04

  • Next message: R. Kym Horsell: "Re: Help with Peg Solitaire 15 hole triangle version"
    Date: Mon, 23 Aug 2004 21:11:06 -0400
    
    

    In June I posted some rather amateurish messages in which my goal was to
    test the consistency of attributed, unbound variables. I wrote that it would
    be better for this test to fail, than it would be for the test to succeed
    when the attributes try to unify their variable with different values.
    Further, I wasn't sure, and am still not sure if as a result of CLP, the
    attributes of one variable can end up comparing other, bound variables.

    I did learn from some support from this newsgroup, and from a recommended
    book, that code snippets which I had posted were not adequate at the time.
    Still in June I concluded my exercise with some modest code that was
    supposed to be better. But because I did not know that Google was indexing
    my messages, I did not decide to post my final code. Here it is:

    lousy_attrib(X) :-
     freeze(X, fail).

    good_attrib(X) :-
     freeze(X, (X = 5)).

    consistent(X) :- nonvar(X).

    consistent(X) :- var(X),
     \+ attvar(X);
     get_attrs(X, Attributes),
     \+ \+ test_attrs(Attributes).

    test_attrs([]).

    test_attrs(att(_, Value, More)) :-
     callable(Value),
     call(Value),
     test_attrs(More).

    test_attrs(att(_, Value, More)) :-
     \+ callable(Value),
     test_attrs(More).

    test_attrs(att(_, Value, More)) :-
     \+ callable(Value),
     test_attrs(More).

    consistent_l([Head | Tail]) :- is_list(Head),
     consistent_l(Head),
     consistent_l(Tail).

    consistent_l([Head | Tail]) :- \+ is_list(Head),
     consistent(Head),
     consistent_l(Tail).

    consistent_l([]).

    consistent_e(E) :- nonvar(E),
     E =.. L,
     consistent_l(L).

    consistent_e(E) :- var(E),
     consistent(E).

    And here is a sample session:

    1 ?- consistent(X).

    X = _G271

    Yes
    2 ?- good_attrib(X), consistent(X).

    X = _G360{freeze = user: (_G360=5)}

    Yes
    3 ?- X = 5, consistent(X).

    X = 5

    Yes
    4 ?- lousy_attrib(X), consistent(X).

    No
    5 ?- X = A + B, consistent_e(X).

    X = _G342+_G343
    A = _G342
    B = _G343

    Yes
    6 ?- X = A + B, lousy_attrib(B), consistent_e(X).

    No
    7 ?-

    Dirk


  • Next message: R. Kym Horsell: "Re: Help with Peg Solitaire 15 hole triangle version"
  • Quantcast