How to print function summary programmatically

I’m curious how to programmatically print the function summary that REPL outputs, i.e.

myFunction doStatic (generic function with 3 methods)

For instance, I’d like to be able to do the following:

function myFunction(a::Int32,b::Int32)
    c = (1 + a) ^ b
    return c
end

function myFunction(a::Int32,b::Float64)
    c = (1 + a) ^ Int32(floor(b))
    return c
end

function myFunction(a::Float64,b::Float64)
    c = (1 + a) ^ b
    return c
end

whatFunction(myFunction)
whatFunction(+)
whatFunction(kron)

and have the following print to the REPL / terminal / notebook:

myFunction (generic function with 3 methods)
+ (generic function with 163 methods)
kron (generic function with 18 methods)

I realize I could write my own function to do this (pull from methods()), but I wanted to check first that I wasn’t missing a built-in. I’ve looked through show, dump, println… I’ve not found anything that replicates the REPL output.

1 Like

I’m not sure I follow entirely. Are you looking to display(myFunction)?

3 Likes

Or show(stdout, “text/plain”, myfunction), which gives you more control over which stream the output goes to than display

4 Likes

I’m not sure I follow entirely. Are you looking to display(myFunction)?

@jameson, well this is interesting. I probably should have gone into more detail, but I didn’t think it necessary.

I’m actually trying to use this functionality in NextJournal.

Here’s a notebook I’ve put together in NextJournal that demonstrates the issue.

For the future reader. Your solution works in REPL, but may not in some online electronic notebooks.

Or show(stdout, “text/plain”, myfunction), which gives you more control over which stream the output goes to than display

@stevengj, thanks! See my reply above to @jameson. Do you think that’s a bug that I should report to NextJournal?