Could a command like MATLAB’s `type` exist in Julia

As a new Julia user I make frequent use of REPL help prompt, and have found @which, typeof() and fieldnames() to be helpful in cases where docstrings don’t have much to offer. In many cases I find I still need to turn to the source to understand how I am supposed to use a method, struct or macro.

In MATLAB I could print the relevant source to the command window easily with the type command. Is it possible for a Julia macro to provide the functionality of MATLAB’s type command?

type filename displays the contents of the specified file in the MATLAB® Command Window.

Perhaps something similar already exists to dump snippets of Julia source code to the REPL? I realize that MATLAB’s “one function per .m file” means that I’ve under specified what I’m asking Julia to do.

I’ve looked for other discussion on this topic but it’s difficult to form a good search query because “type” appears in so many other contexts.

The closest equivalent is the @less macro. The @edit macro might also be of interest.

that’s the entire file right? which is trivial to do but kinda useless in Julia. The only reason this function is not useless in MATLAB is that you have one function per file which is, to be honest, crazy. (and that MATLAB doesn’t have multi-dispatch)


You can easily print source code of a function (method) in Julia, GitHub - timholy/CodeTracking.jl: It's editing-time, do you know where your methods are? provides

@code_string

macro. I have this add @code_src by Moelf · Pull Request #253 · KristofferC/OhMyREPL.jl · GitHub PR, which makes the result printed with syntax highlighting, if you’re into that sort of thing or is already using OhMyREPL.jl

4 Likes