Something like
a = [ones(2),zeros(3)]
function test1(myv; dict = Dict(length(b)=>b for b in a))
return dict[myv] .+ 10
end
When you learn about eval you think it’s a homoiconic code generator thingy. Which it is, but by design, it is highly limited by this only evaluates in global scope. Generally eval is high level stuff for extending modules after the fact, like putting new methods inside of unexported functions.
My experience is if you think you need eval, consider
Step 1.) The power of Dicts, NamedTuples, and closures and dispatch to pass around and access data.
Step 2.) IF that doesn’t work (and it usually does), figure out how macros works and if you need that kind of power.
Step 3.) Finally by this point you may consider eval but more likely you will just redesign your code so you don’t need to do the thing you wanted to do in the first place.