[erlang-questions] records in erlang and error while creating it
Richard Carlsson
richardc@REDACTED
Mon Mar 5 13:10:07 CET 2007
hemant wrote:
> this might be a really stupid question, but at shell I am doing this:
>
> 2> -record(person, {
> 2> firstName = "",
> 2> lastName = "",
> 2> age}).
In the shell, you can only write expressions. You cannot write
function definitions, such as 'f(X) -> X+1.', and you cannot
write declarations (things like '-record(...).', which begin
with a '-').
What happened was that the shell thought you tried to write
an expression that started with a unary minus, just as if
you had written '- f(...)', and it interpreted the part where
you said 'firstName = ""' literally and tried to match the
atom 'firstName' against the empty string '""'. That's why the
error message said 'badmatch'.
You're certainly not the first person to make this kind of
mistake. To write declarations and function definitions, you
need to bring up your text editor and write a module.
/Richard
More information about the erlang-questions
mailing list