% Copyright (C) 2003 Fred Mesnard <fred@univ-reunion.fr>
%
% This file is part of cTI.
%
% cTI is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
%
% cTI is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
% for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
% USA.
%
% For the most up-to-date information see the cTI's web site:
% http://www.cs.unipr.it/cTI/

%% Fred
%% fevrier 2000

:- module(term_size,[term_size/2]).

term_size(X,X):-var(X),!.
term_size(Cte,0):-atomic(Cte),!.
term_size(Terme,Exp):-functor(Terme,_F,N),N>0,size(1,N,Terme,1,Exp).

% list-size:
%term_size([],0).
%term_size([_X|Xs],1+N):-term_size(Xs,N).

size(P,N,_Terme,Exp,Exp):-P is N+1,!.
size(I,N,Terme,E1,E2):-
	I=<N,J is I+1,
	arg(I,Terme,Ai),
	term_size(Ai,Si),
	size(J,N,Terme,E1+Si,E2).

% term_size/4
