It expects the same format in response. Isn’t it inefficient to convert from a string to an atom back into a string? My application and the application I’m talking to get very chatty.
defmodule GoodMacro do
@wow "wow!_"
defmacro boop(val) do
result = "boop_" <> @wow <> val
quote do
unquote(result)
end
end
end
defmodule Cat do
require GoodMacro
def meow() do
GoodMacro.boop(cat)
end
end
The code now no longer relies on the fact that a binary happens to be represented by just a binary in the Elixir AST, meaning that inside GoodMacro.boop/1, result could be altered to other things, like result = {1,@wow, val} or result= %{a: 1, foo: @wow, val: val} etc.
Indeed, performing things once during compilation that would otherwise happen very frequently during runtime is a great opportunity for optimization. But of course, do not do so prematurely .
GoodMacro.boop/1 could be altered later on regardless of how it was initially implemented internally. I actually think the original implementation was cleaner.