如何禁用SMLNJ警告?

mca*_*dre 5 command-line interface sml smlnj

我正在尝试编写命令行脚本,但SML的警告会混淆接口.

文档说使用:

Compiler.Control.printWarnings := false;
Run Code Online (Sandbox Code Playgroud)

但是SMLNJ已将这些重命名为:

Control.printWarnings := false;
Run Code Online (Sandbox Code Playgroud)

这实际上产生了更多的打印输出.

例:

$ cat hello.sml
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
Hello World!
val it = () : unit
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
hello.sml:2.1-2.36 Warning: type vars not generalized because of
   value restriction are instantiated to dummy types (X1,X2,...)
Run Code Online (Sandbox Code Playgroud)

与:

$ cat hello.sml
Control.printWarnings := false;
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
[autoloading]
[library $smlnj/compiler/current.cm is stable]
[library $smlnj/compiler/x86.cm is stable]
[library $smlnj/viscomp/core.cm is stable]
[library $smlnj/viscomp/basics.cm is stable]
[library $smlnj/viscomp/elabdata.cm is stable]
[library $smlnj/viscomp/elaborate.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $smlnj/viscomp/debugprof.cm is stable]
[library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
[library $smlnj/MLRISC/Control.cm is stable]
[library $SMLNJ-MLRISC/Control.cm is stable]
[library $controls-lib.cm(=$SMLNJ-LIB/Controls)/controls-lib.cm is stable]
[library $smlnj/smlnj-lib/controls-lib.cm is stable]
[autoloading done]
val it = () : unit
Hello World!
val it = () : unit
[autoloading]
[autoloading done]
Run Code Online (Sandbox Code Playgroud)

Jes*_*erg 8

首先,您需要修复这些警告,而不是忽略它们.别的什么都是丑陋的习惯!

print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
Run Code Online (Sandbox Code Playgroud)

除此之外,据我所知:没有办法摆脱sml/nj中的自动加载消息.你可以尝试另一个翻译.Poly/ml并没有多说,但我似乎找不到在文件上启动它的方法.Mosml也不会聊太多,在这里你可以在一个文件上启动它(就我所知,它甚至是一个.mlb文件 - 它没有记录).

另一种方法是编译你的文件,然后编写脚本的目的逐渐消失.

你已经弄清楚了一个sml不适合这项工作的情况.


更新.

我发现你可以通过在编译管理器的控制器中将verbose设置为off来实际获得一些方法:

;#set CM.Control.verbose false;
Run Code Online (Sandbox Code Playgroud)

这摆脱了最多,但它仍然打印一些自动加载消息,因为它必须加载CM.Control结构.它只会在事后关闭.但是文档还建议您可以设置环境变量CM_VERBOSE

CM_VERBOSE=false sml foo.sml
Run Code Online (Sandbox Code Playgroud)

这让它几乎安静.使用此来源

val _ = print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
Run Code Online (Sandbox Code Playgroud)

生成以下输出:

$ CM_VERBOSE=false sml foo.sml 
Standard ML of New Jersey v110.72 built: Wed May 12 15:29:00 2010] 
[opening foo.sml] 
Hello World!
Run Code Online (Sandbox Code Playgroud)

注意每次val _ = ...都没有写val it = () : unit.