The function executes before the return value is available to display. So the only way to do what you want would be to capture the output, using e.g. the low-level redirect_stdout
function or a higher-level package like IOCapture.jl, in order to save it to print later.
(Alternatively, of course, you can print whatever you want from the function itself, e.g. call display(s)
before your println
statement to mimic the REPL display, and then suppress additional output in the REPL by ending the line in a ;
.)