erlang是否在python或';'中有'pass'之类的空语句 在C?
有时我想测试代码而不用杀死所有进程,清理ets表并从头开始.
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("")
Run Code Online (Sandbox Code Playgroud)
leg*_*cia 10
原子ok通常用于:
try
ets:new(TableName,[options])
catch
% if the ets table has been initialized in the earlier test.
error:badarg->
ok
end.
Run Code Online (Sandbox Code Playgroud)
它并不严格地说是"空语句",因为它确实有效:它成为表达式的返回值.例如,try如果表创建成功,上面的表达式将返回ETS表id,ok如果失败则返回原子.当然,只要你忽略了返回值,那没关系.
编辑:你需要这样做,因为在Erlang中没有语句,一切都是表达式并返回一个值.