Hi! I’m trying to contribute to Base by making sort(x) print "Hello World" before returning the correct answer. Is there a good workflow without building Julia locally?
(edited for concision)
You can use Revise.jl for Julia base with Revise.track(Base). See What Revise can track.
1 Like
Thanks! Here’s what I’ve ended up doing:
- Open a Julia REPL
-
using Revise(or add to.julia/config/startup.jl) Revise.track(Base)-
@edit sort([3,2,1])to see that source file is running (/Applications/Julia-1.8.0-DEV-7ccc83ebaf.app/Contents/Resources/julia/share/julia/base/sort.jl) - edit that source directory in a text editor to instert
println("hello world") - run
sort([3,2,1])in the original REPL
A manual way to do this, if you want something quick, eg to test an idea, and don’t want to edit directly in base is.
mysort.jl
sort(v::AbstractVector; kws...) = (println("Hello world!"); sort!(copymutable(v); kws...))
And
julia> Base.include(Base.Sort, "mysort.jl");
julia> sort([2,1])
Hello world!
2-element Vector{Int64}:
1
2
Thanks! In this case, I want to contribute my changes upstream so editing the file directly is nice, but it’s also often nice not to. Is there a way to set up Revise to track mysort.jl in your example?
The docs for includet suggest that this is the way to do it.
Revise.track(Base.Sort, "mysort.jl"; mode=:eval, skip_include=false)
And this works. I’m not sure how valuable it is. Maybe it is.