I did not know/understand this, thx.
It is similar to my second example but more clarifying, thx again.
Coming back to my initial post, how can I create a function within a function, specify it programmatically and return it?
function fun()
foo(x::Real) = x
f = :foo
@eval $f(x::Complex) = x'
return foo
end
bar = fun()
varinfo()
name size summary
–––––––––––––––– ––––––––––– ––––––––––––––––––––––––––––––––––––––––––––––––
Base Module
Core Module
InteractiveUtils 307.688 KiB Module
Main Module
bar 0 bytes (::var"#foo#1") (generic function with 1 method)
foo 0 bytes foo (generic function with 1 method)
fun 0 bytes fun (generic function with 1 method)
I would like bar to have two methods, the ones that currently have foo and bar itself.