for each function or macro to count how many functions are recursively included in the top level function
I am not sure what this means.
If you want to count the number of function calls in the code, you would need a full fledged code walker.
However, for the simple meaning of the number of top-level forms in the file, the problem is quite tractable.
I am not aware of an existing program that does that, but it does not sound hard to roll it:
(defun read-file-as-string (file-name)
(with-open-file (in file-name :external-format charset:iso-8859-1)
(let ((ret (make-string (1- (file-length in)))))
(read-sequence ret in)
ret)))
:external-format
may not be necessary.
See
.
(defun count-lines (string)
(count #\Newline string))
See count
.
(defun count-forms (string)
(with-input-from-string (in string)
(loop with *read-suppress* = t
until (eq in (read in nil in))
count t)))
See
.
(defun file-code-stats (file-name)
(let* ((file-text (read-file-as-string file-name))
(lines (count-lines file-text))
(forms (count-forms file-text)))
(format t "File ~S contains ~:D characters, ~:D lines, ~:D forms (~,2F lines per form)"
file-name (length file-text) lines forms (/ lines forms))
(values (length file-text) lines forms)))
(file-code-stats "~/lisp/scratch.lisp")
File "~/lisp/scratch.lisp" contains 133,221 characters, 3,728 lines, 654 forms (5.70 lines per form)
133221 ;
3728 ;
654