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

标签 lisp common-lisp metrics code-metrics lines-of-code

我正在寻找可以为我生成 lisp 程序中每个函数的代码行统计数据的程序。在 Lisp 中,这意味着每个函数或宏要计算有多少函数被递归地包含在顶级函数中。

任何指针将不胜感激。

最佳答案

for each function or macro to count how many functions are recursively included in the top level function

我不确定这是什么意思。

如果你想计算代码中的函数调用次数,你需要一个完整的 code walker .

不过,对于文件中顶层表单数量的简单含义,这个问题还是比较容易处理的。 我不知道有这样做的现有程序,但它听起来并不难:

(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 可能不是必需的。 见

.

(defun count-lines (string)
  (count #\Newline string))

参见 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)))

.

(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

关于lisp - 寻找一个可以帮助我为 lisp 程序生成每个函数统计代码行的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48264593/

相关文章:

session - Google Analytics 用户指标是否等同于 Webtrends Analytics 访问者指标?

emacs - 当我尝试在 emacs 中安装自动完成时出现错误

optimization - 查找质因数太慢或崩溃

language-agnostic - 如何说服您的开发人员编写简短的方法?

linux - 我如何使用(需要:PACKAGE) in clisp under Ubuntu Hardy?

lisp - Common Lisp 未绑定(bind)变量

java - 无法查看使用 spring 指标注释捕获的指标

if-statement - `if` 的替代实现 - 难以理解的行为

C++ 代码和来自 C 的对象?

list - 反转 LISP 中列表的前 n 个元素