Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 221V/ab1a608d4ffd7efc949712ff41c2e48d to your computer and use it in GitHub Desktop.
Save 221V/ab1a608d4ffd7efc949712ff41c2e48d to your computer and use it in GitHub Desktop.
%% посмотреть во что компилится макрос
iex(14)> defmodule T do
...(14)> def f(fun, arg), do: apply(String, :"#{fun}", [arg])
...(14)> end |> elem(2) |> :beam_lib.chunks([:abstract_code]) |> elem(1) |> elem(1) |> get_in([:abstract_code]) |> elem(1) |> :erl_syntax.form_list |> :erl_prettypr.format |> IO.puts
warning: redefining module T (current version defined in memory)
iex:14
-file("iex", 14).
-module('Elixir.T').
-compile(no_auto_import).
-export(['__info__'/1, f/2]).
-spec '__info__'(attributes | compile | functions |
macros | md5 | module | deprecated) -> any().
'__info__'(module) -> 'Elixir.T';
'__info__'(functions) -> [{f, 2}];
'__info__'(macros) -> [];
'__info__'(attributes) ->
erlang:get_module_info('Elixir.T', attributes);
'__info__'(compile) ->
erlang:get_module_info('Elixir.T', compile);
'__info__'(md5) ->
erlang:get_module_info('Elixir.T', md5);
'__info__'(deprecated) -> [].
f(Vfun@1, Varg@1) ->
erlang:apply('Elixir.String',
erlang:binary_to_atom(<<case Vfun@1 of
Vrewrite@1
when
erlang:is_binary(Vrewrite@1) ->
Vrewrite@1;
Vrewrite@1 ->
'Elixir.String.Chars':to_string(Vrewrite@1)
end/binary>>,
utf8),
[Varg@1]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment