Update: Consistency check.
From: Dirk Mittler (mdirk_at_sympatico.ca)
Date: 10/27/04
- Next message: Dirk Mittler: "Re: Update: Consistency check."
- Previous message: Gertjan van Noord: "Re: Prolog and Regexp"
- Next in thread: Dirk Mittler: "Re: Update: Consistency check."
- Reply: Dirk Mittler: "Re: Update: Consistency check."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 27 Oct 2004 13:48:57 -0400
>From time to time I've revisited my exercise, to write a Prolog program
which, given a term, will do its best to determine if that term is
consistent, as far as attributes of unbound variables go. Having said that,
I recognize that (1) I'm still a novice at Prolog, and (2) for entire
expressions, there is no universal way to do this. Therefore my program
passes expressions until they can be proven impossible, by choice.
Yet, it's understood that to Prolog in general,
X = X + 1
is entirely plausible, especially if your version accepts infinite, or
cyclic terms. In that case this is just a cyclic term with itself as its
first argument, and a (1) attached to it via a meaningless (+) symbol. This
is due to the fact that this (+) symbol does not necessarily imply a
mathematical function in Prolog. My program does not change this, or assume
Math is being used itself.
I had posted earlier code, and find that because this code was seen once, I
need to update it from time to time. The reality is that I only occupy
myself with this wonderful language from time to time, and here is my latest
version:
lousy_attrib(X) :-
freeze(X, fail).
good_attrib(X) :-
freeze(X, (X = 5)).
% consistent_s/1 will change argument !!!
consistent_s(X) :- nonvar(X).
consistent_s(X) :- var(X),
\+ attvar(X);
get_attrs(X, Attributes),
test_attrs(Attributes).
test_attrs([]).
test_attrs(att(_, Value, More)) :-
callable(Value),
consistent_call(Value),
test_attrs(More).
test_attrs(att(_, Value, More)) :-
\+ callable(Value),
test_attrs(More).
% consistent_l/1 will change arguments !!!
consistent_l([]).
consistent_l([Head | Tail]) :- is_list(Head),
consistent_l(Head),
consistent_l(Tail).
consistent_l([Head | Tail]) :- \+ is_list(Head),
consistent_s(Head),
consistent_l(Tail).
consistent_call(E) :-
catch(E, _, true),
E =.. L,
consistent_l(L).
% Always use consistent/1 or consistent_all/1 !!!
consistent_all(List) :- \+ \+ consistent_l(List).
consistent(E) :- callable(E), !,
\+ \+ consistent_call(E).
consistent(E) :- nonvar(E),
E =.. L,
\+ \+ consistent_l(L).
consistent(E) :- var(E),
\+ \+ consistent_s(E).
- Next message: Dirk Mittler: "Re: Update: Consistency check."
- Previous message: Gertjan van Noord: "Re: Prolog and Regexp"
- Next in thread: Dirk Mittler: "Re: Update: Consistency check."
- Reply: Dirk Mittler: "Re: Update: Consistency check."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|