Using the @memoize macro

macro memoize(fun::Expr)
local call = fun.args[1]
local name = call.args[1].args[1]
local arg1 = call.args[1].args[2]
local arg1_name = arg1.args[1]
local arg1_type = arg1.args[2]
local return_type = call.args[2]
local body = fun.args[2]
    quote
let cache = Dict{$(esc(arg1_type)), $(esc(return_type))}()
global function $(esc(name))($(esc(arg1_name))::$(esc(arg1_type)))::$(esc(return_type))
if haskey(cache, $(esc(arg1_name)))
cache[$(esc(arg1_name))]
else
cache[$(esc(arg1_name))] = $(esc(body))
end
end
end
end
end

Hello. Am trying to modify the above code to solve this problem
##To generalize the @memoize macro and make it more robust (still for functions
with a single argument) by checking whether the argument and return types
are specified or not. If they are not, use the Any type instead of the argument or
return type (or both) in the Dict that acts as the cache.

Have you tried Memoize.jl?