Code: Select all
domains
sl=symbol*
predicates
nondeterm parent(symbol,symbol)
nondeterm getChildren(symbol,sl,sl)
nondeterm member(symbol,sl)
nondeterm add(sl,sl,sl,sl)
nondeterm dfs(sl,sl,symbol)
clauses
parent(a,b).
parent(a,c).
parent(a,d).
parent(b,e).
parent(b,f).
parent(c,f).
parent(c,g).
parent(e,h).
parent(e,i).
parent(f,j).
dfs(OPEN,CLOSE,END):-
OPEN=[],!,fail
;
OPEN=[X|_],X=END,!,true
;
getChildren(X,[],ChL),CLOSE2=[X|CLOSE],add(ChL,OPEN,CLOSE2,OPENF),
dfs(OPENF,CLOSE2,END).
getChildren(X1,ChL,ChLF):-
parent(X1,Ch),not(member(Ch,ChL)),!,ChL2=[Ch|ChL],
getChildren(X1,ChL2,ChLF)
;
ChLF=ChL.
member(X,[X|_]).
member(X,[_|T]):-
member(X,T).
add([],OPEN,_,OPENF):-OPENF=OPEN,!.
add(ChL,OPEN,CLOSE,OPENF):-
ChL=[H|T],not(member(H,OPEN)),not(member(H,CLOSE)),!,
OPEN2=[H|OPEN],add(T,OPEN2,CLOSE,OPENF)
;
ChL=[_|T],add(T,OPEN,CLOSE,OPENF).
goal
%getChildren(a,[],CHLF).
dfs([a],[],b).
However, I get the following error:
the variable is not bounded in this clause X