[erlang-questions] Please review this basic Erlang doc?

Ulf Wiger ulf@REDACTED
Fri Feb 2 12:48:40 CET 2007

Den 2007-02-01 23:17:11 skrev Robert Baruch <autophile@REDACTED>:

> Hi all,
> In learning Erlang as an expert procedural developer, but novice
> functional developer, I had to organize my thoughts about Erlang and
> how to think in functional terms. So, I wrote a document, and decided
> that maybe it's useful to other Erlang beginners who are also
> procedural experts.
> With that in mind, does anyone want to take a look at this document
> and send in comments? It's not finished, so I'd welcome any suggestions.

Nice effort. Have you received any feedback from fellow Java programmers?

Here are a few minor comments:

Page 6

   "The “ok” at the end is just the shell
   indicating that the function didn’t cause an error."

Actually, no. The 'ok' is the return value from the called
function. The hello:hello() function ends by calling
io:fwrite/2, which returns 'ok'. That's the value you're
seeing. Consider the following shell dialogue:

1> lists:reverse([1,2,3]).

   "Finally, to exit the shell, we call the function halt/0."

It's better to practice using init:stop(), although
halt/0 and halt/1 have their uses.

When you get into using more complex programs, init:stop()
will give applications like mnesia a chance to close down
properly. This will save you from dets and log files being
repaired when you restart.

   "From this brief sample, we can see that Erlang has a
   global namespace – c/1 and halt/0 are in that global
   namespace. We will touch on this subject more later."

c/1 and halt/0 are actually quite different, in that
c/1 is synonymous to c:c/1 *in the shell only*.

The VM has some built-in functions that could be said to
be part of a global namespace. halt/0 is such a function.
The shell has some "built-ins" for convenience, but that's
just a name substitution thingy built into the shell's
eval loop.

Page 9

   "The variables that begin with an underscore are
   actually ignored, so the names are really just
   comments. You could just as easily have written
   {_ , Second, _} but that may not be as clear,
   depending on the context."

Underscores are always ignored. The variables that begin
with an underscore are actually real variables. The
linter interprets them as "don't care" patterns, but the
compiler does not. This is important to know, because if
you would write your pattern as:

   {_Any, Middle, _Any} = Arg

you'd notice (after much confusion) that only 3-tuples
with identical first and third elements will avoid a
badmatch error. The leading underscore is just a
convention - it is a legal variable name.

Page 13

If statements actually only accept guards

if Guard1 ->
    Guard2 ->
    true ->

Page 15

   "Note that because the the recursive call
   to go/1 is the last thing that go/1 does."

One may note that go/0 also performs a tail call (although not recursive).

Ulf W

> The document doesn't aim to be an Erlang tutorial, but rather to
> guide the developer in thinking functionally. So once I'm sure a
> functional concept has been explained, I do a lot of referring the
> reader to the reference manuals.
> Anyway, here it is: http://chuffyrodents.org/erlang.pdf
> --Rob
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger

More information about the erlang-questions mailing list