Consider the analogue of analogue of a frequently used LISP pattern in
Julia, a let over a function definition (eg for memoization):

f(a) = @show(a)

let table = Dict()
  function memoized_f(a)
    if (haskey(table, a))
      table[a]
    else
      result = f(a)
      table[a] = result
      result
    end
  end
end

Now if I try to use memoized_f, I get

julia> VERSION
v"0.3.1"
julia> memoized_f(1)
ERROR: memoized_f not defined

Is this a bug, or is this pattern not allowed? Of course, I can
(partially) work around this with

memoized_f = 
  let table = Dict()
    (a) -> begin
      if (haskey(table, a))
        table[a]
      else
        result = f(a)
        table[a] = result
        result
      end
    end
  end

but that has its own issues (not a generic function, suboptimal
performance).

Best,

Tamas

Reply via email to