Why can't methods be defined inside a `let` block?

let creates a “hard” scope, see Scope of Variables · The Julia Language.

To define a method in a let block, you need to manually use the global keyword:

# Numbers use isequal
let x = isequal
    global preferred_equal_fn(::Type{T}) where {T <: Number} = x
end
7 Likes