Way to cache output from immutable input?

Lets say you have code like:

function foo(x::Float64, scaling::Number=2)
  x * scaling
end

foo(4.0, 1)   # unique call

foo(4.0, 1)   # repeat call
foo(4.0, 1)   # repeat call
foo(4.0, 1)   # repeat call

foo(4.0)      # unique call
foo(4.0, 2)   # unique call

Is there a cache system available to store all the repeat calls?


  • in the code above, obviously you could just store it as a variable
  • the interesting problem is when they’re called at different levels of a call tree like:
    • a calls b calls c calls d calls ...

https://github.com/simonster/Memoize.jl?

whoops, yea…

just saw: