"for" will not build a list if you don't use its output value and that's
always the case if you have it between expressions, such as:
a = 1
for .... do ... end
b = 2
In this case, because you never use the result of for, we never build a
list. Enum.map will build a list regardless but I doubt it would matter to
the point of being noticeable.
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
On Sun, Oct 30, 2016 at 3:04 PM, Luke Imhoff <[email protected]> wrote:
> Since the output of the `Enum.each`, `for`, and `Enum.map` is effectively
> ignored because only the entries in the defs_table (
> https://github.com/elixir-lang/elixir/blob/master/lib/
> elixir/src/elixir_def.erl#L207) matter, is there a performance benefit to
> replacing any `for` or `Enum.map` around `def` with `Enum.each` so the
> compilation doesn't spend the time and memory creating a list that'll just
> be throw away?
>
> On Sun, Oct 30, 2016 at 2:13 AM, José Valim <[email protected].
> br> wrote:
>
>> Def, like defmodule, module attributes and friends, is a side-effect. It
>> stores information in the module table. Returned quoted expressions
>> wouldn't quite work because we would need to collect them until the end.
>> Check the expanded code and it may clarify things a bit.
>>
>> On Sunday, October 30, 2016, Luke Imhoff <[email protected]> wrote:
>>
>>> I had thought that `def` returned (the equivalent [because it's really
>>> in elixir_bootstrap.erl] of a) quoted block and in order for a `def` to
>>> count in a loop, you'd need either a `for` comprehension, or `Enum.map`, so
>>> that the `quote` from each `def` is concatenated together to be merged into
>>> the caller's quoted form, but [Postgrex.Message.decode_auth_type/1 uses
>>> Enum.each](https://github.com/elixir-ecto/postgrex/blame/mas
>>> ter/lib/postgrex/messages.ex#L370-L372). How are all the `def`s inside
>>> the `Enum.each` being preserved when `Enum.each` doesn't return the value
>>> of each function call? This is related to https://github.com/KronicDe
>>> th/intellij-elixir/issues/472.
>>>
>>> --
>>> 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/ms
>>> gid/elixir-lang-core/a768af02-fdc1-45be-ad69-e0661f79139b%40
>>> googlegroups.com
>>> <https://groups.google.com/d/msgid/elixir-lang-core/a768af02-fdc1-45be-ad69-e0661f79139b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>>
>>
>> *José Valim*
>> www.plataformatec.com.br
>> Skype: jv.ptec
>> Founder and Director of R&D
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "elixir-lang-core" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/elixir-lang-core/rbAlgKeavJU/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/elixir-lang-core/CAGnRm4KW5Pn6%2Byzvz-9gSx6OCepwscj3WT5J
>> O9RB%2Bo%2B4%2BcFG-g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KW5Pn6%2Byzvz-9gSx6OCepwscj3WT5JO9RB%2Bo%2B4%2BcFG-g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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/CAFmZThqhMA_5xJc%3DiTjuB4CDWzXE5PUF5%
> 2BeQZ6WuKAvw4BFj3w%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAFmZThqhMA_5xJc%3DiTjuB4CDWzXE5PUF5%2BeQZ6WuKAvw4BFj3w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAGnRm4KwF%3DaejvTxFBFgUJb9Q-WMSNnesrBzD%2BhcJuEu_w-P1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.