[erlang-questions] Help for a newbie...
Richard A. O'Keefe
Thu May 9 03:10:31 CEST 2013
I wonder if the original poster would have been so puzzled had
the error message been
"A function cannot begin with 'case'."
which would have hinted that the compiler thought this was
the beginning of a (new) function.
The last parser I wrote, I switched from Yacc to plain old
recursive descent and found it much easier to generate
error messages that I found helpful.
The original poster should also note that
Multi-word identifiers in Erlang are normally separated by
spaces unless they have to be compatible with something else.
There is a problem with the calls to nthtail/2 (just because
it's in the Erlang standard library doesn't mean it's a good
name): the arguments are in the wrong order. In any case,
you don't need it.
[Time,_|Dishes] = string:tokens(User_Entry, ","),
of "morning" -> process_morning(Dishes)
; "night" -> process_evening(Dishes)
; _ -> io:fwrite("error\n")
You might prefer to eliminate the '_ -> io:fwrite(...)' case;
if there's no match the 'case' will crash, and that's just what
we want. Unless this is an assignment, in which case do what
the assignment says.
More information about the erlang-questions