Erlang记录表达式忽略警告 [英] Erlang record expression ignored warning

查看:178
本文介绍了Erlang记录表达式忽略警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

    Check#tab_info{login_errors = 0},
    {ok, PID};

但是当我尝试对其进行编译时,我会收到警告:

But i get warning when i try to compile it:

表达式的结果将被忽略(通过将表达式分配给_变量来抑制警告)

这是怎么回事?我该如何解决?

What's wrong? How can i fix it?

谢谢。

推荐答案

好,编译器会告诉您到底是什么问题:)您创建了一个新的 #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 the Check 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.

您要将表达式绑定到

NewCheck = Check#tab_info{...}
{ok, Pid, NewCheck}

作为补充,如果您执行了函数调用但未绑定返回值的任何值,编译器都不会抱怨,因为该函数可能会有副作用,这可能就是您首先调用该函数的原因。

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.

这篇关于Erlang记录表达式忽略警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆