home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / TERMSIZE.LF < prev    next >
Text File  |  1996-06-04  |  813b  |  27 lines

  1. % Return a list containing the values of all features of X:
  2. feature_values(X) -> map(project(2=>X),features(X)).
  3.  
  4. % Sum all the elements in a list:
  5. sum([V|Vs]) -> V+sum(Vs).
  6. sum([]) -> 0.
  7.  
  8. term_size(X) -> N |
  9.    V<<-@,                  % Create an anonymous persistent
  10.                            % term for the result.
  11.    ( V<<-term_explore(X,Seen), % Calculate the size.
  12.      fail                  % Remove effects of calculation.
  13.    ;
  14.      N=copy_term(V)        % Copy the result back to a normal
  15.    ).                      % logical term.
  16.  
  17.  
  18. term_explore(X,Seen) -> V |
  19.    ( X===Seen,             % Skip already-counted nodes.
  20.      !,
  21.      V=0
  22.    ;
  23.      FV=feature_values(X), % Get the features of X.
  24.      X<-Seen,              % Mark X as having been counted.
  25.      V=1+sum(map(term_explore(2=>Seen),FV))
  26.    ).
  27.