How to print the code of functions in Julia to REPL?

In Julia, many of the base and related functions are also written in pure Julia and the code is readily available. You can run through the repository or locally downloaded files and see how this function is written / implemented. But I think there is some built-in method that does this for you, so you can write in the REPL or Jupyter Notebook something like:

@code functioninquestion()

and you get something like:

functioninquestion(input::Type) some calculations return end

without paging. I just don't remember the method or the call. I have read the Reflection / Introspection section of the Guide, but I can't seem to use anything. I tried to methods

, methodswith

, code_lowered

, expand

and can not force them to give what I want -

+2


source to share


3 answers


While this may not be what the OP is looking for, it is @less

very convenient to read the underlying code (which is why I use it very often). For example,

julia> @less 1 + 2

      

gives



+(x::Int, y::Int) = box(Int,add_int(unbox(Int,x),unbox(Int,y)))

      

which corresponds to the line given

julia> @which 1 + 2
+(x::Int64, y::Int64) at int.jl:8

      

+7


source


This is currently not supported, but will likely be in the future.



+7


source


@edit functioninquestion()

will open your editor to host the specified method. It probably wouldn't be difficult to take the same information that was used @edit

and use it to open the file and skip the method definition and then display it directly in the REPL (or Jupyter). EDIT: When I was replying, someone else mentioned @less

which seems to do exactly what you want.

+4


source







All Articles