>
> While I personally think this behaviour is documented (because the two 
> passes compilation is documented as part of the macro system as well as the 
> fact that structs are expanded during compile time)


Where exactly is this documented?

On Sunday, July 17, 2016 at 5:04:43 PM UTC+3, José Valim wrote:
>
>  
>
>>     Regarding #2 - Without a clearer understanding of the formal
>> specification of the language (ala #1) that tells me otherwise, I
>> still think (your corrected) Version #1 should be legal Elixir but
>> perhaps just requires a different mechanism for identifying when the
>> Module/Struct is fully defined. A two pass system could absolutely
>> still work this way.
>
>
> Since this seems to be the contention point, let's try to understand why 
> this is the only possible way for this to work. Imagine you have this code:
>
> variable = System.get_env("DEFINE_BAR")
>
> defmodule Foo do
>
>   if variable in ~w(1 true) do
>
>     defmodule Bar do
>
>     end
>
>   end
>
> end
>
>  
> If the module Bar was defined during compilation, Bar would be *always* 
> defined, because compilation does not know the value of the variable nor it 
> would evaluate the if (since it depends on runtime values). Code that is 
> expanded, is always expanded, even if inside a conditional. If the module 
> was defined during expansion then the module would always be defined.
>
> In other words, a struct expansion that happens at compile time, cannot 
> depend on values that are in the same context and will be defined only at 
> runtime. That's the same reason why you can't invoke a function in the same 
> context you define it. The reason why multiple modules work is because we 
> first expand both modules and then we execute them. 
>
> While I personally think this behaviour is documented (because the two 
> passes compilation is documented as part of the macro system as well as the 
> fact that structs are expanded during compile time), I would agree it may 
> take a while to build the intuition around it and we could very likely 
> benefit from more examples and discussions.
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/12252c12-44fb-4974-8bd6-ababf274233a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to