Memoize.jl
Memoize.jl copied to clipboard
Functional usage?
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?
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.