gpt4 book ai didi

erlang - 如果不为零则打印一个值

转载 作者:行者123 更新时间:2023-12-02 04:47:54 27 4
gpt4 key购买 nike

如果它大于零,我需要打印出一个值:

info({mail, BoxPid, Messages, MessageCount, MessageDropCount}, Req, S) ->
if MessageDropCount > 0 ->
io:format("dropped=~p~n", [MessageDropCount]);
true -> true
end,
...,
{loop, Req, S};

我不喜欢 if 表达式的 true -> true 部分。有办法避免吗?有成语吗?

最佳答案

If Then page at the ErlangCentral wiki建议这些模式:

  • [io:format("dropped=~p~n", [MessageDropCount]) || MessageDropCount > 0]
  • MessageDropCount > 0 andalso io:format("dropped=~p~n", [MessageDropCount])
  • MessageDropCount =< 0 orelse io:format("dropped=~p~n", [MessageDropCount])

关于erlang - 如果不为零则打印一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19440411/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com