我正在尝试编写命令行脚本,但是SML的警告使界面变得模糊。
文档上说要使用:
Compiler.Control.printWarnings := false;
但SMLNJ后来将其重命名为:
Control.printWarnings := false;
这实际上会产生更多的打印输出。
示例:
$ 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,...)
对比:
$ 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]
发布于 2011-11-19 02:41:10
首先,您需要修复这些警告,而不是忽略它们。其他的都是丑陋的习惯!
print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
除此之外,据我所知:没有办法摆脱sml/nj中的自动加载消息。你可以试试其他的解释器。Poly/ml没有说太多,但是我似乎找不到一种在文件上启动它的方法。Mosml也不经常聊天,在这里您可以在一个文件上启动它(据我所知,甚至是一个.mlb文件--它没有文档记录)。
另一种方法是编译你的文件,然后脚本的目的就消失了。
您偶然发现了sml不是适合该工作的工具的情况。
更新。
我发现,实际上可以通过在编译管理器的控制器中将verbose设置为off来实现此目的:
;#set CM.Control.verbose false;
这去掉了大部分,但是它仍然打印一些自动加载消息,因为它必须加载CM.Control结构。它只会在事后闭嘴。但是,文档还建议您可以设置环境变量CM_VERBOSE
CM_VERBOSE=false sml foo.sml
这让它变得近乎安静。使用这个源码
val _ = print "Hello World!\n";
val _ = OS.Process.exit(OS.Process.success);
生成以下输出:
$ 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!
请注意val _ = ...
不要让它每次都写入val it = () : unit
。
https://stackoverflow.com/questions/8186848
复制相似问题