
% database.pl

:- dynamic defconcept/2, defprimconcept/2.

% defconcept(C DEF) 

% defprimconcept( C DEF/nil)

% (assert WFF)  
%    implies(WFF,WFF)
%    implies(WFF,DEF) <= (defconcept C DEF) 
%    not(and(A,B))    <= disjoint(A,B)
/*
defconcept(animal,or(mamal,fish)).
defconcept(carnivore,and(animal,all(eats,meat))).
defconcept(omnivore,and(animal,some(eats,meat))).
defconcept(vegetarian,and(animal,all(eats,not(meat)))).
*/
expand_definition(C,DEF,NewDEF):-
	expand_def(DEF,NewDEF,[C]).

expand_def(A,_,ED):-
	atom(A),
	member(A,ED),!,
	nl,write('Error: can\'t expand '),write(A),
	write(' after expanding '),write(ED),nl,!,fail.

expand_def(A,B,ED):-
	atom(A),
	not(member(A,ED)),
	defconcept(A,DEF),!,
	expand_def(DEF,B,[A|ED]).

expand_def(A,A,ED):-
	atom(A),
	not(member(A,ED)),!.	
	 
expand_def(A,B,ED):-
	A =.. [F|L],
	expand_def_list(L,M,ED),
	B =.. [F|M],!.

expand_def_list([],[],_):- !.
expand_def_list([A|B],[AA|BB],ED):-
	expand_def(A,AA,ED),
	expand_def_list(B,BB,ED),!.
