gpt4 book ai didi

syntax-error - 标准ML中的LPAREN语法错误

转载 作者:行者123 更新时间:2023-12-03 08:06:44 30 4
gpt4 key购买 nike

尝试在ML中运行此程序时,出现连续错误 pop 窗口:

fun find(s,file) =
let fun findHelper(true, true, ch, w, file, acc, acc2) = TextIO.output(TextIO.stdOut, acc2^"\n")
| findHelper(b1, b2, ch, w, file, acc) = ch = valOf(TextIO.input1(TextIO.file)) acc2^str(ch)
if ch = "" then
if w = acc then b1 = true
else acc = ""
else if ch = "\n" then b2 = true
else acc^str(ch)


in
findHelper(false, false, "", s, file, "", "")
end

错误代码为:
    project.sml:61.3 Error: syntax error: inserting  LPAREN
project.sml:65.12 Error: syntax error: inserting RPAREN

老实说,我已经插入了很多括号,但我什至不知道为什么会出现此错误。错误集中在“if ch =”“then”周围,但是ch的另一个实例没有错误,所以我不知道为什么它会错误一个而不是另一个。

最佳答案

语法错误是您的内部函数包含以下形式的表达式

 A if B then C else D

(其中A的形式为“x = y”)。要顺序计算表达式,必须使用分号运算符和括号,因此:
(A; if B then C else D)

但是,这只会使您克服语法错误,而对其他方面没有太大帮助。该代码没有多大意义。您似乎以某种方式假设您可以使用 =来分配变量-事实并非如此。 SML是一种功能语言,并且变量是不可变的。您要使用的是递归。

关于syntax-error - 标准ML中的LPAREN语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29559020/

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