仅使用SML/NJ打印输出

11

我正在尝试使用SML/NJ,使用sml < source.sml运行代码,但它会输出太多信息。

例如,这是source.sml的内容:

fun fac 0 = 1
  | fac n = n * fac (n - 1)
val r = fac 10 ;
print(Int.toString(r));

这是输出结果:

Standard ML of New Jersey v110.77 [built: Tue Mar 10 07:03:24 2015]
- val fac = fn : int -> int
val r = 3628800 : int
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
3628800val it = () : unit
Suppress "val it" output in Standard MLHow to disable SMLNJ warnings?SMLNJ want to remove "val it = () : unit" from every print statement execution中,我获得了一些关于如何抑制它们的提示。
我执行CM_VERBOSE=false sml < $filename并在代码中添加了一行Control.Print.out := {say=fn _=>(), flush=fn()=>()};,但仍然有一些消息:
Standard ML of New Jersey v110.77 [built: Tue Mar 10 07:03:24 2015]
- 3628800

我该如何仅打印输出结果?

1个回答

4

sml 命令旨在交互使用。我认为你最好从你的程序中构建一个独立的可执行文件。

有几个选项:

  1. If you are relying on SML/NJ extensions, or if you simply cannot use another ML implementation, you can follow the instructions in this post to build an SML/NJ heap image that can be turned into a standalone executable using heap2exec.

  2. A better option might be to use the MLton compiler, another implementation of Standard ML. It lacks a REPL, but unlike SML/NJ it requires no boilerplate to generate a standalone executable. Building is as simple as issuing:

    $ mlton your-program.sml
    $ ./your-program
    3628800
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接