[erlang-questions] Why does this compile without warnings/errors?

Gianfranco Alongi gianfranco.alongi@REDACTED
Tue Jul 9 21:07:06 CEST 2013


1. it is used - in a match

It is used to match against the first bound instance (the one passed
in the function head).
if loop/1 is called as loop(<0.123.0>) then, this is the <0.123.0>
that will be matched against in the receive.

2. The compiler can not know a priori the value of Foo when you pass
as a function Argument.
So, if you do Foo = 5 , it might be a valid match.




On Tue, Jul 9, 2013 at 9:02 PM, Yves S. Garret
<yoursurrogategod@REDACTED> wrote:
> I'm looking at this code:
>
> loop(ExoSelf_PId) ->
>   receive
>     {ExoSelf_PId, {Id, Cx_PId, ActuatorName, Fanin_PIds}} ->
>       loop(Id, Cx_PId, ActuatorName, {Fanin_PIds, Fanin_PIds}, [])
>   end.
>
> Now, what I'm not quite 'getting' is why the compiler is not complaining
> about
> ExoSelf_PId.  First of all, it's not used anywhere.  Second of all, if it's
> used, it's
> used to bind (to an already bound) variable and that's the message that's
> received
> to this process.  If I were to pass in Foo and then do Foo = 5, the compiler
> would
> tell me that that is impossible, so what is different in this case?
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list