3

我知道文档解释了这些工具,但我不明白解释。有人可以提供一两个例子吗?

4

1 回答 1

5

其中erl_tidy,最简单的方法 - 也是最直接的,如果你的源目录中一直在运行,那就是直接从 Eshell 中使用它,如

$ erl
1> m(erl_tidy).
% output snipped
2> erl_tidy:dir().  % recursively tidy the present directory and its children
% output snipped
3> erl_tidy:dir("", [{recursive, false}]).  % just the present directory
reading module `./bad.erl'.
made backup of file `./bad.erl'.
writing to file `./bad.erl'.
4>

在这种情况下,bad.erl

-module(bad).
-compile(export_all).

bad(0)->1;bad(1)->2;bad(N)->3.bad()->0.

对整理好的

-module(bad).

-compile(export_all).

bad ( 0 ) -> 1 ; bad ( 1 ) -> 2 ; bad ( N ) -> 3 . bad ( ) -> 0 .

...好吧,这不是魔术师:-)

erl_tidy也可以通过 的参数调用erl,如

$ # unix prompt
$ erl -s erl_tidy dir
tidying directory `./wesnoth'.
tidying directory `./wesnoth/Vix'.
tidying directory `./wesnoth/Vix/utils'.
...

erl_lint然而完全不同。要了解如何使用它,首先要了解这个字符串评估示例中发生了什么。 erl_lint旨在作用于 Erlang 源代码的中间表示,而不是它的字符串。

于 2011-08-02T04:56:53.600 回答