[erlang-questions] Warning: the call to node/0 has no effect

Björn Gustavsson bjorn@REDACTED
Fri May 10 13:19:49 CEST 2019


On Fri, May 10, 2019 at 12:00 PM Monk Boy <boyofmonk@REDACTED> wrote:
>
> Hi
>
> When compile the code , I got a message:
>
> ```
> src/http_qmonitor.erl:58: Warning: the call to node/0 has no effect
> ```
>
> the code is
>
> ```
>     N = length([node()|nodes()]),
> ```
>

Internally, the compiler does a series rewrites. First we have:

V1 = node(),
V2 = nodes(),
N = length([V1|V2])

Then the compiler rewrites the code like so:

V1 = node(),
V2 = nodes(),
N = length(V2) + 1

since the length of the list does not depend on the value value of V1.

It then notices that V1 is no longer used, issues a warning and
rewrites the code like so:

V2 = nodes(),
N = length(V2) + 1

/Björn

--
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list