memoize icon indicating copy to clipboard operation
memoize copied to clipboard

defmemo/defmemop suppresses compiler warnings

Open tim2CF opened this issue 6 years ago • 3 comments
trafficstars

example (Memoize 1.3.0) suppresses obvious compiler warnings

defmodule Greetings do
  use Memoize
  defmemo hello(name) when is_binary(name) do
    :ok = DoesNotExist.foo()
    "Hello, #{name}!"
  end
end

tim2CF avatar Nov 26 '18 13:11 tim2CF

I think Memoize uses Code.eval_quoted in __before_compile__/1, but I don't know how to fix it.

melpon avatar Nov 26 '18 15:11 melpon

not use __before_compile__/1 ? :)

tim2CF avatar Nov 26 '18 15:11 tim2CF

I just ran into a problem that I suspect is related, so I'll report it here: Elixir warns about unused imports for functions only called from inside a defmemo:

defmodule Five do
  def five() do
    5
  end
end

defmodule Eleven do
  use Memoize
  import Five, only: [five: 0]

  defmemo eleven() do
    6 + five()
  end
end

yields a warning: unused import Five.

Unfortunately, I also don't know how to fix it :) There has to be a way to tell Elixir to treat blocks of code passed to macros as, well, normal code, right? (I'm on Elixir 1.7.1, Erlang 20)

Thanks for an excellent library by the way. I really like how well memoize works with eg long-running computations or asynchronous operations. I looked at some of the source and I imagine that it wasn't easy to get that right. Hats off! I also like how you can gradually scale a memoize use case into a full blown cache, with expiry and all that.

eteeselink avatar Dec 13 '18 08:12 eteeselink