It is useful to peak at an array when debugging a function. However, the macro @show prints arrays like vectors. How to print arrays in the correct REPL way?
OK. It’s worth mentioning that, when I search for “julia print arrays” on google, a ton of suggestions come up (show, println, print, show, showall, showcompact and @show), none of which do what I want (pretty-printing an array as the REPL does).
Coupled with the lack of a debugger, this makes for a very frustrating experience for a casual user that wants to port their script from matlab and wants to print an array inside a loop to check it’s correct. So, if someone finds this topic by searching on google for “julia print arrays”, here’s the answer you’re looking for: display.
If you look in the manual for “pretty printing,” you’ll find the section explaining the difference between show(io, x) (terse one-line display, used e.g. in print) and show(io, "text/plain", x) (multiline verbose pretty printing, used e.g. in REPL output and display).
The three-argument show may be preferable to display if you specifically want text output (display can use e.g. graphical output for some types if the UI supports it, though you can also supply a MIME type to display) or if you want to output to a specific file/stream/buffer (not STDOUT).
Thanks @jbrea I found a way to print it in a nice way. The problem is that it is not simple and intuitive. Why forcing people to know print, display, show - and with different arguments like io or stringbuffer (if you want show to print to string and not to stdout).
I wouldn’t mind if those extra stuff were supposed to be used only by super-users or library developers. But that’s not the case. You need to know it in the simplest case - just to be able to print things nicely.