Memoize.jl icon indicating copy to clipboard operation
Memoize.jl copied to clipboard

Functional usage?

Open tbenst opened this issue 4 years ago • 1 comments

Thanks for this package! I'm looking for higher order function memoization, e.g. I'd like to be able to do: memoized_f = @memoize expensive_function_from_package, but this triggers ERROR: LoadError: @memoize must be applied to a method definition.

As a workaround, I currently do

@memoize function memoized_f(args...)
  expensive_function_from_package(args...)
end

But not sure that this is fully generic. Is this a fundamental restriction due to the function/method implementation?

tbenst avatar May 14 '20 21:05 tbenst

You mean that you would like to memoize a call? Like

function my_function()
   @memoize some_expensive_call(...)
end

? That's currently outside of the realm of this package, but it could be done I suppose if the macroexpansion looked up a cache in some global variable. Like get!(global_cache_dict, @__MODULE__, @__LINE__) or something.

cstjean avatar Oct 28 '20 16:10 cstjean