Question

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("")
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top