Warning: the call to node/0 has no effect

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Warning: the call to node/0 has no effect

Monk Boy
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()]),
```

I can't understand what is it

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Warning: the call to node/0 has no effect

Stuart Welham
Hi

I'm not certain but I would guess because you are not actually using the result of node() here and this creates a new list where it's not needed.

How about refactoring this to be

N = length(nodes()) + 1

-Stuart

On Fri, 10 May 2019 at 11:00, Monk Boy <[hidden email]> 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()]),
```

I can't understand what is it
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Warning: the call to node/0 has no effect

Björn Gustavsson-4
In reply to this post by Monk Boy
On Fri, May 10, 2019 at 12:00 PM Monk Boy <[hidden email]> 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
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Warning: the call to node/0 has no effect

Monk Boy
thanks,I got it!!!

On Fri, May 10, 2019 at 7:20 PM Björn Gustavsson <[hidden email]> wrote:
On Fri, May 10, 2019 at 12:00 PM Monk Boy <[hidden email]> 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

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions