The illegal guard statement comes from calling the ets:first(Cal) function from within an if statement guard. so if ets:first(Cal) =/= '$end_of_table' ->
is not going to compile correctly. Guard statements only have a small set of functions that can be used, read about them here.
Also if statements are a little different in Erlang vs. other languages. One clause at least must evaluate to true. The Documentation on if statements explains this behavior, and how an error is thrown if no clause evaluates to true.
So moving the ets:first(Cal)
outside of the if statement and adding a catch all true case to your code, should work:
Res = ets:first(Cal),
if
Res =/= '$end_of_table' ->
Event = ets:first(Cal),
{TimeAtStart, Ref} = Event,
NowTime = now(),
Ms = timer:now_diff(NowTime, TimeAtStart)div 1000;
true -> ok %% you need a default clause
end,
However, if it was me doing my school project, I would try to use the ets:info function to check the size of the table, and do it inside of a case statement. Checkout the Documentation on the ets:info function, and the case statement.
Just FYI: I don't think I have used an if statement the entire time I have been programming in Erlang.