Hello,
I use memoization frequently and have run into two problems with the move
to Julia 0.5.0.
The first is not too serious and I hope can be fixed readily. The first
time I memoize a function, a warning is generated like this:
julia> using Memoize
julia> @memoize f(a) = a+1
WARNING: symbol is deprecated, use Symbol instead.
in depwarn(::String, ::Symbol) at ./deprecated.jl:64
in symbol(::String, ::Vararg{String,N}) at ./deprecated.jl:30
in @memoize(::Expr, ::Vararg{Expr,N}) at
/Users/ers/.julia/v0.5/Memoize/src/Memoize.jl:14
in eval(::Module, ::Any) at ./boot.jl:234
in eval(::Module, ::Any) at
/Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
while loading no file, in expression starting on line 0
(::#28#f) (generic function with 1 method)
More significantly, if I want multiple dispatch on a function name, the
second instance creates a problem and the definition is rejected. Here I
define a factorial function that always returns a BigInt. The first
function definition succeeds but the second one fails:
julia> @memoize function Factorial(n::Integer)
if n<0
throw(DomainError())
end
if n==0 || n==1
return big(1)
end
return n * Factorial(n-1)
end
(::#35#Factorial) (generic function with 1 method)
julia> @memoize function Factorial(n::Integer,k::Integer)
if n<0 || k<0 || k > n
throw(DomainError())
end
if k==n
return big(1)
end
return n * Factorial(n-1,k)
end
ERROR: cannot define function Factorial; it already has a value
in macro expansion; at /Users/ers/.julia/v0.5/Memoize/src/Memoize.jl:103
[inlined]
in anonymous at ./<missing>:?
julia> Factorial(10) # this works
3628800
julia> Factorial(10,2) # but this doesn't
ERROR: MethodError: no method matching (::##35#Factorial#2)(::Int64,
::Int64)
Closest candidates are:
#35#Factorial(::Integer) at
/Users/ers/.julia/v0.5/Memoize/src/Memoize.jl:113