Erlang 记录表达式忽略警告
我有以下代码:
Check#tab_info{login_errors = 0},
{ok, PID};
但是当我尝试编译它时,我收到警告:
表达式的结果被忽略(通过将表达式分配给 _ 变量来抑制警告)
出了什么问题?我该如何修复它?
谢谢。
I have following code:
Check#tab_info{login_errors = 0},
{ok, PID};
But i get warning when i try to compile it:
the result of the expression is ignored (suppress the warning by assigning the expression to the _ variable)
What's wrong? How can i fix it?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,编译器会准确地告诉您出了什么问题:) 您创建了一个新的
#tab_info
记录,但从未将其绑定到任何变量。因此,该代码毫无意义,编译器是这样告诉您的。更改Check
变量(或更准确地说,创建一个新变量)不会产生任何效果,除非您返回它。Check
不是一个全局变量,就像在命令式语言中那样。此外,更改作为函数参数接收的变量不会导致调用者如何看待该变量。您想要将表达式绑定到某个变量,然后用它做一些有意义的事情。
附带说明一下,如果您执行了函数调用并且没有将返回值绑定到任何内容,则编译器不会抱怨,因为该函数可能有副作用,这可能是您首先调用该函数的原因。
Well, the compiler is telling you exactly what's wrong :) You create a new
#tab_info
record, but never bind it to any variable. The code is therefore meaningless and the compiler is telling you so. Changing theCheck
variable (or more correctly, creating a new one) won't have any effect unless you return it.Check
is not a global variable, like it might be in imperative languages. Also, changing a variable you receive as an argument to a function, will not result in a change in how the caller sees the variable.You want to bind the expression to some variable and then do something meaningful with it.
As a side note, if instead you did a function call and did not bind the return value to anything, the compiler would not complain as the function might have side-effects and this might be the reason you called the function in the first place.