With Documenter.jl
, each code block evaluates in its own scope:
Every doctest block is evaluated inside its own
module
. This means that definitions (types, variables, functions etc.) from a block can not be used in the next block.
Is it possible to define explanatory methods in code blocks so that they don’t leak into the global environment?
For example, how can I achieve the following?
module MWE
"""
foo(x)
Example method definition:
```jldoctest
julia> MWE.foo(x::Int) = @info "new method" x
julia> foo(42)
┌ Info: new method
└ x = 42
```
"""
function foo(x)
@info "fallback method" x
end
"""
bar(x)
```jldoctest
julia> foo(42)
┌ Info: fallback method
└ x = 42
```
"""
function bar(x) end
end # module MWE
Note that fixing the doctests with Documenter
causes the new method to be used in bar
’s docstring, instead of the fallback method.