[ library(apply_macros) | Reference Manual | Alphabetic Index ]
sumnodes(+Pred, +Term, ?AccIn, ?AccOut)
Call Pred on all Subterms of Term and collect a result in Accumulator
Description
The traversal is depth-first and left-to-right
Modules
This predicate is sensitive to its module context (tool predicate, see @/2).
Examples
	sumnodes(vars, s(1,t(X,2),[Y]), [], [X,Y]).
	where
	    vars(X, Vars, [X|Vars]) :- var(X), !.
	    vars(_, Vars, Vars).
	or even more elegant using grammar rules:
	sumnodes(vars, s(1,t(X,2),[Y]), [X,Y], []).
	where
	    vars(X) --> {var(X)} -> [X];[].