寻找一个可以帮助我为lisp程序生成每个函数统计信息的代码行的程序

use*_*970 0 lisp metrics common-lisp code-metrics loc

我正在寻找可以为我生成lisp程序中每个函数的代码行的统计信息的程序.在Lisp中,这意味着每个函数或宏可以计算顶级函数中递归包含的函数数量.

任何指针都将非常感激.

sds*_*sds 6

对于每个函数或宏来计算顶级函数中递归包含的函数数量

我不确定这意味着什么.

如果要计算代码中函数调用的数量,则需要一个完整的代码遍历器.

但是,对于文件中顶级表单数量的简单含义,问题非常容易处理.我不知道有一个现有的程序,但它听起来并不难:

(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)))
Run Code Online (Sandbox Code Playgroud)

:external-format可能没有必要.看到

.

(defun count-lines (string)
  (count #\Newline string))
Run Code Online (Sandbox Code Playgroud)

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)))
Run Code Online (Sandbox Code Playgroud)

看到

.

(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
Run Code Online (Sandbox Code Playgroud)