Skip to content

Instantly share code, notes, and snippets.

@jrevels
Created May 23, 2018 21:21
Show Gist options
  • Save jrevels/1a41f9f1682acf324fc0e4b002bc6a77 to your computer and use it in GitHub Desktop.
Save jrevels/1a41f9f1682acf324fc0e4b002bc6a77 to your computer and use it in GitHub Desktop.
julia> f(x) = println("hello")
f (generic function with 1 method)
julia> callf(x) = f(x)
callf (generic function with 1 method)
julia> const callf_lowered = @code_lowered callf(1)
CodeInfo(:(begin
nothing
Core.SSAValue(0) = (Main.f)(x)
return Core.SSAValue(0)
end))
julia> @generated function g(x)
return deepcopy(callf_lowered)
end
g (generic function with 1 method)
julia> g(1)
hello
julia> f(x::Int) = println("goodbye")
f (generic function with 2 methods)
julia> g(1)
goodbye
julia> f(1)
goodbye
julia> f(1.0)
hello
julia> g(1.0)
hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment