[erlang-questions] getting started with IO: question about syntax

Romain Lenglet rlenglet@REDACTED
Mon Oct 30 11:35:24 CET 2006


David Clarke Stevens wrote:
> I know this is a typical noob question, but I'm just getting
> into Erlang and can't seem to get it working correctly.  I've
> written a simple factorial function that I want to display
> text with, but the compiler complains about syntax...any help
> would be appreciated!!
>
>     -module(factorial).
>     -export([main/0]).
>
>     main() ->
>         io:format("The factorial of 5 is: ").

The line above should terminate with a comma, not a period.

>         fac(5).
>
>     fac(X) ->
>         if X == 1 ->
>             1;
>         else ->
>             X * fac(X - 1)
>         end.
>
> The compile error I'm getting is:
> 21> c(factorial).
> ./factorial.erl:6: syntax error before: '.'
> ./factorial.erl:8: Warning: function fac/1 is unused
> error

-- 
Romain LENGLET



More information about the erlang-questions mailing list