You can confirm it is done by the Erlang compiler using the beam_file
<https://github.com/hrzndhrn/beam_file> lib for example (or `@compile :S`)
and check the emitted byte code:

defmodule Foo do
  def foo, do: 1 + 2 * 3
end
|> BeamFile.byte_code!()
|> elem(5)
|> Enum.filter(&(elem(&1, 1) == :foo))

[
  {:function, :foo, 0, 11,
   [
     {:line, 1},
     {:label, 10},
     {:func_info, {:atom, Foo}, {:atom, :foo}, 0},
     {:label, 11},
     {:move, *{:integer, 7}*, {:x, 0}},
     :return
   ]}
]



Le jeu. 7 août 2025 à 05:19, José Valim <jose.va...@gmail.com> a écrit :

> I believe we do it for certain functions in Elixir's stdlib and the Erlang
> compiler (which we invoke) does it too.
>
>
> *José Valimhttps://dashbit.co/ <https://dashbit.co/>*
>
>
> On Wed, Aug 6, 2025 at 10:00 PM benjamin...@gmail.com <
> benjaminschult...@gmail.com> wrote:
>
>> AFAIK, then the compiler does not perform const evaluation.
>>
>> iex(9)> quote(do: 1+2*3)
>> {:+, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]],
>>  [1, {:*, [context: Elixir, imports: [{2, Kernel}]], [2, 3]}]}
>>
>> iex(10)> quote(do: 1+2*3)
>> 7
>>
>> Are there any plans to implement this, if not what is the recommended
>> approach to do this, when working on an AST.
>>
>> --
>> 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 elixir-lang-core+unsubscr...@googlegroups.com.
>> To view this discussion visit
>> https://groups.google.com/d/msgid/elixir-lang-core/b7b48090-7022-4f14-b92b-2732272fc151n%40googlegroups.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/b7b48090-7022-4f14-b92b-2732272fc151n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4L2mF_o2j0aE_MYCC7rXX8qZdpdHe_b3zew0g_fY7ztfA%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4L2mF_o2j0aE_MYCC7rXX8qZdpdHe_b3zew0g_fY7ztfA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/elixir-lang-core/CANnyohYi8UXrd%2BMVg5FvkSVGjqUFa%2BhVD8xetRqQkv8cPy8O1Q%40mail.gmail.com.

Reply via email to