gpt4 book ai didi

SML/NJ 使用 CM.make : "Error: illegal character"

转载 作者:行者123 更新时间:2023-12-04 18:30:13 31 4
gpt4 key购买 nike

我正在尝试从 Shipman 的 Unix System Programming with Standard ML 编译以下程序:

structure Main=
struct

fun main(arg0, argv) =
(
case argv of
[] => ()
| (first::rest) =>
(
print first;
app (fn arg => (print " "; print arg)) rest;
print "\n"
);

OS.Process.success
)

val _ = SMLofNJ.exportFn("echo", main)
end

我的 .cm 文件看起来像:
group is
$/basis.cm
echo.sml

当我跑 CM.make "echo.sml";我收到以下错误消息:
gotchops@gotchops-vm:~/Documents/USPwSML/Ch2/echo$ CM_ROOT=echo.cm sml
Standard ML of New Jersey v110.80 [built: Fri Sep 16 22:36:30 2016]
- CM.make "echo.sml";
[autoloading]
[library $smlnj/cm/cm.cm is stable]
[library $smlnj/internal/cm-sig-lib.cm is stable]
[library $/pgraph.cm is stable]
[library $smlnj/internal/srcpath-lib.cm is stable]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
[scanning echo.sml]
echo.sml:7.11 Error: illegal character: [
echo.sml:7.12 Error: illegal character: ]
echo.sml:1.2-1.16 Error: syntax error: deleting STRUCTURE ML_ID
echo.sml:6.9 Error: syntax error: inserting RPAREN
echo.sml:8.17-8.19 Error: syntax error: deleting COLON COLON
echo.sml:11.14 Error: syntax error: replacing LPAREN with RPAREN
echo.sml:11.32-11.34 Error: syntax error: deleting FILE_NATIVE
echo.sml:11.47 Error: syntax error: inserting LPAREN
echo.sml:12.16-12.19 Error: syntax error: replacing FILE_NATIVE with LPAREN
echo.sml:13.10 Error: syntax error: inserting LPAREN
echo.sml:17.30-17.35 Error: syntax error: deleting FILE_NATIVE
echo.sml:19.1 Error: syntax error found at EOF
val it = false : bool

但是,当我运行 use "echo.sml"; 时从顶层我可以编译得很好。有谁知道怎么了?

最佳答案

我认为您只是在错误的文件上调用 CM。应该在 .cm 上调用它文件,而不是 .sml文件。由于 CM 正在寻找 CM 语法,而不是 SML 语法,因此它会向您抛出语法错误。

来自新版CM手册[pdf ]:

2.3 Invoking CM

Once a library has been set up as shown in the example above, one can load it into a running interactive session by invoking function CM.make. If the name of the library’s description file is, say, fb.cm, then one would type

CM.make "fb.cm";


以这种方式使用 CM,我能够毫无问题地编译您的示例,然后像这样运行程序:
$ sml @SMLload=echo.x86-darwin a b c d e
a b c d e

(遵循 documentation on SML_OF_NJ.exportFn )。

关于SML/NJ 使用 CM.make : "Error: illegal character",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39582011/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com