Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an erlang null statement

Tags:

null

erlang

Does erlang has null statement like 'pass' in python or ';' in C ?
Sometimes I want to test the code without the pain of killing all the processes, cleaning the ets tables and starts all over.

try
    ets:new(TableName,[options])
catch
    % if the ets table has been initialized in the earlier test.
    error:badarg->
        % I want an empty statement instead of an ugly io:format
        io:format("")
like image 925
Paul Liang Avatar asked Dec 20 '22 15:12

Paul Liang


1 Answers

The atom ok is often used for that:

try
    ets:new(TableName,[options])
catch
    % if the ets table has been initialized in the earlier test.
    error:badarg->
        ok
end.

It's not strictly speaking a "null statement", since it does have an effect: it becomes the return value of the expression. For example, the above try expression will return an ETS table id if table creation succeeds, and the atom ok if it fails. Of course, as long as you are ignoring the return value, that doesn't matter.

EDIT: You need to do this as there are no statements in Erlang, everything is an expression and returns a value.

like image 50
legoscia Avatar answered Dec 22 '22 05:12

legoscia