Tuesday, June 26, 2007


Atoms, Variable, what they are and what you can do with them ?

Atoms are what you'll find strange at the first look, you may ask yourself
continously, but where the hell this thing is defined !!

Relax and just read the following words, atoms are just there to document your code...
So they can appear anywhere, have no special meaning or just may be funny !
You'll find them most of the time tagging tuples, example:

test() ->
% code that fails
{error, "Can't find file"}.

This way you can try to match 'error', and bind a Variable to the reason:

case test() of
{ok, Result} ->
{error, Reason} ->
io:format("Error: because ~p~n", [Reason])

Simple isn't it ?

No comments: