Nirox
Nirox

Reputation: 13

Erlang syntax error before: 'end' in line 55

Cant find the syntax error, i searched for misplaced/missing ";" , "," , "end" and also searched for missing parentheses but no luck. Any ideas?

PD: Sorry for bad English and Spanglish code

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).

Upvotes: 0

Views: 274

Answers (1)

Pouriya
Pouriya

Reputation: 1626

You have a syntax error in receive clause.

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

receive statement is used for reading Erlang messages of the process. Here you are not waiting for any message and you are doing something in body of receive clause! If you don't want to check the message but you want to do something after receiving first message, I recommend to use _ for pattern matching:

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

Actually you can have no receive clause, but like this:

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

But you can't write code in receive clause without any pattern matching.

Upvotes: 1

Related Questions