【发布时间】:2020-06-23 12:55:02
【问题描述】:
所以,我正在用 Erlang 制作一个井字游戏,它不断抛出语法错误,我不知道为什么。它发生在检查 X 是否获胜的函数中。代码如下:
checkX(["xxx" | _]) -> true;
checkX([_ | ["xxx" | _]]) -> true;
checkX([_ | [_ | ["xxx" | _]]]) -> true;
checkX(Board) ->
if
xy(Board, {0, 0}) == 120 and xy(Board, {0, 1}) == 120 and xy(Board, {0, 2}) == 120 -> true;
xy(Board, {1, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {1, 2}) == 120 -> true;
xy(Board, {2, 0}) == 120 and xy(Board, {2, 1}) == 120 and xy(Board, {2, 2}) == 120 -> true;
xy(Board, {0, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {2, 2}) == 120 -> true;
xy(Board, {2, 0}) == 120 and xy(Board, {1, 1}) == 120 and xy(Board, {0, 2}) == 120 -> true;
true -> false
end.
(xy/2 是一个函数,它接受一个板(它是一个字符串列表)和一个元组并返回元组中位置的字符。)当我编译它时它一直抛出这个错误:
board.erl:68: syntax error before '=='
(第 68 行是 if 语句中的第一个条件。)
有人知道这是为什么吗?
【问题讨论】:
标签: erlang syntax-error