[erlang-questions] 1st day of Erlang: what is wrong with this code
Tue Jul 14 07:44:09 CEST 2015
On 07/12/2015 03:19 AM, avinash D'silva wrote:
> Error in process <0.58.0> with exit value:
> That was the error. But how would I find the cause of the error?
> In java or other languages that I worked earlier, I would get a "Type
> Mismatch Error".
I'm fairly certain that this is how Erlang spells "Type Mismatch Error".
To see this in action, try compiling this program that makes use of
test(Arg) when is_list(Arg) ->
test(Arg) when is_atom(Arg) ->
If you run the function with a list, atom, and then binary, you can see
that the first two are accepted, but there's no function to handle a
binary, so the program dies:
Erlang/OTP 18 [erts-7.0] [source] [smp:2:2] [async-threads:10] [hipe]
Eshell V7.0 (abort with ^G)
2> spawn(test, test, ["hello"]).
3> spawn(test, test, [hello]).
4> spawn(test, test, [<<"hello">>]).
=ERROR REPORT==== 13-Jul-2015::22:34:24 ===
Error in process <0.53.0> with exit value:
(For information about spawn/3, check out
http://www.erlang.org/doc/man/erlang.html#spawn-3 . I'm spawning the
function, rather than calling it directly, as the shell does a bit of
interpretation of the error, so it's less obvious that what is happening
here is the same thing that was happening with the program that you were
having trouble with.)
Erlang error reports are hard to read at first. With more experience,
they'll become easy to read. I'm also pretty sure that this is the place
to ask questions when you have them. :)
Good luck, and have fun!
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the erlang-questions