【问题标题】:Printing only print output with SML/NJ仅使用 SML/NJ 打印打印输出
【发布时间】:2015-07-25 13:00:38
【问题描述】:

我正在尝试使用 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

如何只打印输出?

【问题讨论】:

    标签: sml smlnj ml


    【解决方案1】:

    sml 命令旨在以交互方式使用。在我看来,你最好从你的程序中构建一个独立的可执行文件。

    有几个选项:

    1. 如果您依赖 SML/NJ 扩展,或者如果您根本无法使用其他 ML 实现,您可以按照this post 中的说明构建可以转换为独立的 SML/NJ 堆映像使用heap2exec 执行。

    2. 更好的选择可能是使用 MLton 编译器,这是标准 ML 的另一种实现。它缺少 REPL,但与 SML/NJ 不同,它不需要样板来生成独立的可执行文件。构建就像发行一样简单:

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

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      相关资源
      最近更新 更多