January 2020
Intermediate to advanced
532 pages
13h 31m
English
So far, we did not pay much attention to the arguments or keyword arguments being passed to the function. Care must be taken when any of those arguments are mutable. Why? Because our current implementation uses the arguments as the key of the dictionary cache. If we mutate the key of a dictionary, it could lead to unexpected results.
Suppose that we have a function that takes 2 seconds to run:
# This is a slow implementationslow_sum_abs = (x::AbstractVector{T} where {T <: Real}) -> begin sleep(2) sum(abs(v) for v in x)end
Knowing that it's quite slow, we happily memoize it as usual:
sum_abs = memoize(slow_sum_abs)
Initially, it seems to work perfectly, as it has always been:
However, we are shocked ...
Read now
Unlock full access