[erlang-questions] my first crash.dump

Tuncer Ayaz <>
Tue May 5 19:58:09 CEST 2015


On Mon, May 4, 2015 at 12:34 PM, Tuncer Ayaz wrote:
> On Mon, May 4, 2015 at 11:04 AM, Peter J Etheridge wrote:
> > dear list,
> > in learning Erlang i am trialling Intellij IDEA.
> > as a test, i entered from p.165 of joe's book, his module fac1.
> > although no errors were evident in what i had transcribed,
> > when i ran debugger i received my first;
> > erl_crash.dump
> > 3,258 typos found.
> > from just 9 lines of joe's code?
> > any clues?
>
> For reference, can you post the code here?
>
> Also, what Erlang version did you use?

Here's what Peter sent me and forgot to CC the list:

-module(fac). %fac1 from p.165 of joe's book
-author("BB").
-include_lib("kernel/include/file.hrl"). %another experiment
%% API
-export([main/1]).

main([A])->
    I = list_to_integer(atom_to_list(A)),
    F = fac(I),
    io:format("factorial ~w = ~w~n", [I,F]),
    init:stop().

fac(0) -> 1;
fac(N) -> N*fac(N-1).

I don't know if this is exactly the code from the book, but it's easy
to see where some confusion might arise.

main/1 accepts a list of a single atom to later use as the argument
for fac/1. Maybe fac.erl is meant to be a valid escript as well.

$ erl
> c(fac).
{ok,fac}
> fac:main(['2']).
factorial 2 = 2

If you export fac/2, you can call it like this:

> fac:fac(2).
2

Also, I don't see where file.hrl would be required, so you can omit
that. You'd include it only for the record declarations contained
within (#file_info, #file_description).


More information about the erlang-questions mailing list