之前的 Erlang 语法错误:第 55 行中的 'end'

Posted

技术标签:

【中文标题】之前的 Erlang 语法错误:第 55 行中的 \'end\'【英文标题】:Erlang syntax error before: 'end' in line 55之前的 Erlang 语法错误:第 55 行中的 'end' 【发布时间】:2018-12-22 22:02:00 【问题描述】:

找不到语法错误,我搜索了错位/丢失的“;” , "," , "end" 并且还搜索了丢失的括号但没有运气。 有什么想法吗?

PD:抱歉英文和西班牙文代码不好

partida(ID,Tablero,Turno,Name1,Psocket1,Name2,Psocket2,SpectList) ->
 case (Psocket1 == " ") of
 true -> F = fun() -> case mnesia:read(juegos,ID) of
        [P1] ->
            case mnesia:read(nombre,P1#juegos.jg1) of
                [] -> exit(normal);
                [A] -> P2 = A#nombre.psocket
            end,
            case mnesia:read(nombre,P1#juegos.jg2) of
                [] -> exit(normal);
                [B] -> P3 = B#nombre.psocket
            end,
            Res = P1#juegos.jg1,P2,P1#juegos.jg2,P3,P1#juegos.spect;
         _  -> Res = ok,exit(normal)                         
        end,
        Res end,
        atomic,Arg = mnesia:transaction(F),
        partida(ID,Tablero,Turno,element(1,Arg),element(2,Arg),element(3,Arg),element(4,Arg),element(5,Arg))
end,
receive
    case Jugada of
        [Pj,"bye"] -> ok;
        [Pj,F]   -> Posicion = element(1,string:to_integer(F)),
                    case (Name1 == Pj) and ((Turno rem 2) == 1) of
                        true -> case not(Posicion == error) and  (Posicion < 10) of
                                    true -> ok;%%jugada valida
                                    _  -> ok %%Jugada ilegal
                                end;
                        false ->ok %%No es tu turno
                    end,
                    case (Name2 == Pj) and ((Turno rem 2) == 0) of
                        true -> case (not(Posicion == error) and (Posicion < 10)) of
                                    true ->ok; %%jugada valida
                                     _ -> ok %%Jugada ilegal
                                end;
                        false -> ok %%No es tu turno
                    end
    end
end, %% Line 55
ASD = get_spects(ID),partida(ID,Tablero,Turno,Name1,Psocket1,Name2,Psocket2,ASD).

【问题讨论】:

接收语法似乎有问题。 【参考方案1】:

receive 子句中有语法错误。

1> case oops of _ -> ok end. % correct
ok
2> receive (case oops of _ -> ok end) end.
* 1: syntax error before: 'end'

receive 语句用于读取进程的 Erlang 消息。在这里,您不是在等待任何消息,而是在 receive 子句的正文中做某事!如果你不想查看消息但又想在收到第一条消息后做点什么,我建议使用_ 进行模式匹配:

3> receive _ -> (case oops of _ -> ok end) end.
%% Waits for a message

其实你可以没有receive子句,但是像这样:

4> receive after 1000 -> done end. %% Sleeps 1000 ms and does not care about any incoming message
done

但是你不能在没有任何模式匹配的receive子句中编写代码。

【讨论】:

以上是关于之前的 Erlang 语法错误:第 55 行中的 'end'的主要内容,如果未能解决你的问题,请参考以下文章

Inflector.php 第 265 行中的 FatalErrorException:语法错误,意外 ':',期待 ';'要么 ''

Erlang得到错误** 1:语法错误之前:'->'**

之前的 Erlang 语法错误:'end'

为啥 erlang spawn 函数调用中出现语法错误 - “之前的语法错误:')'”?

Erlang,使用警卫之前的语法错误

为啥 Erlang 中的模式匹配记录会抛出错误