SciML / RuntimeGeneratedFunctions.jl

Functions generated at runtime without world-age issues or overhead
https://docs.sciml.ai/RuntimeGeneratedFunctions/stable/
MIT License
99 stars 15 forks source link

Cannot read variable in local scope #70

Open raythurnvoid opened 9 months ago

raythurnvoid commented 9 months ago
using DataFrames
using Dates

using RuntimeGeneratedFunctions
RuntimeGeneratedFunctions.init(@__MODULE__)

w = Base.get_world_counter()

function Base.show(io::IO, mime::MIME"text/plain", df::AbstractDataFrame; kwargs...)
    fn = @RuntimeGeneratedFunction(:(
        (v, i::Int, j::Int) -> begin
            println(mime) # <- This fails
            typeof(v) <: DateTime ? Dates.format(v, "dd-mm-yyyy HH:MM") : v
        end
    ))

    Base.invoke_in_world(w, Base.show,
        io,
        mime,
        df;
        formatters=fn,
        kwargs...
    )
end

The result of the code above is:

UndefVarError: mime not defined

Am i doing something wrong?