[erlang-questions] Newbie help please with variable unsafe in 'receive' & variable unused

Vlad Dumitrescu vladdu55@REDACTED
Thu Sep 29 16:34:32 CEST 2016


Hi!

What you probably want to do is

loop(Orbiter1) ->
    Coordinates = receive
        {Orbiter1, Coordinates} -> Coordinates
    end,
    {X, Y, Z} = Coordinates,
    io:format("Coordinates: ~p~n", [Coordinates]),
    io:format("X: ~p, Y: ~p, Z: ~p~n", [X, Y, Z])
    loop(Orbiter1).

regards,
Vlad


On Thu, Sep 29, 2016 at 4:22 PM, Donald Steven <t6sn7gt@REDACTED> wrote:

> Hi everyone,
>
> Can someone please put me out of my (extended) misery?  The part of the
> code that's causing the problem is:
>
> =============================
>
> loop(Orbiter1) ->
>
>     receive
>
>         {Orbiter1, Coordinates} -> X = element(1, element(1,
> Coordinates)), Y = element(2, element(1, Coordinates)),
>                                    Z = element(3, element(1, Coordinates))
>     end,
>
>         io:format("Coordinates: ~p~n", [Coordinates]),
>         io:format("X: ~p, Y: ~p, Z: ~p~n", [X, Y, Z])
>
>     loop(Orbiter1).
>
> =============================
>
> which produces the error:
>
> base.erl:48: variable 'Coordinates' unsafe in 'receive' (line 35)
> base.erl:37: Warning: variable 'X' is unused
> base.erl:37: Warning: variable 'Y' is unused
> base.erl:38: Warning: variable 'Z' is unused
>
> {"init terminating in do_boot",{undef,[{base,main,[]
> ,[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
> init terminating in do_boot ()
>
> =============================
>
> Thanks for your help.
>
> Don
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160929/cc01f639/attachment.htm>


More information about the erlang-questions mailing list