next up previous
Next: node2path in Action Up: No Title Previous: Effect of Adding Parent

Extracting the Path from the Node

In the last example, the node

n(ls, n(cc, n(gp, n(bs,-1))))

clearly contains the information we need to recover the path. The following algorithm converts a node into a (reversed) path. Observe how its definition is almost completely independent of the manner in which nodes have been implemented.

node2path(N,[SN]) :-
 node_state_of(N,SN),
 node_parent_of(N,-1),
 !.

node2path(N,[SN|Y]) :-
 node_state_of(N,SN),
 node_parent_of(N,P),
 node2path(P,Y).



Mike Rosner
Fri Mar 5 16:50:53 MET 1999