melpon/memoize

defmemo/defmemop suppresses compiler warnings

Opened this issue · 3 comments

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

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

not use __before_compile__/1 ? :)

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.