You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library has no dependencies other than the Nim standard library.
About
Use print the same way you would use echo for print-debugging. It prints objects the "Nim way" with syntax highlighting. Even with refs, pointers, or cycles!
import print
let a =3
print a
a =3
The "Nim way"
It prints data structures in the same way you would create them in Nim source code. Ideally you can take what it prints out and just copy paste that into code again and it should compile in many cases.
let
a =3
b ="hi there"
c ="oh\nthis\0isit!"
d =@[1, 2, 3]
d2 = [1, 2, 3]
f = Foo(a:"hi", b:@["a", "abc"], c:1234)
print a, b, c, d, d2, f
If you are piping to a file it will detect not-a-terminal and give you plain ascii instead.
Smart indention
It will try to print out everything in one line, but it if it does not fit it will create indentation levels. Max width is based on current terminal max width.
g2 = Bar(a: "hi a really really long string", b: @["a", "abc"], c: 1234)
print g2
Stuff echo does not do well
It will also print nils, refs, and pointers.
g2=Bar(
a: "hi a really really long string",
b: @["a", "abc"],
c: 1234
)
let
p1: ptrint=nil
p2: ref Foo =nil
print p1, p2
p1=nil p2=nil
var three =3var pointerToThree =cast[pointer](addr three)
print pointerToThree
pointerToThree=0x00000000004360A0
And even cycles!
It will also stop recursing repeating structures:
type Node =refobject
data: string
next: Node
var n = Node(data:"hi")
n.next = n
print n
n=Node(data: "hi", next: ...)
About
Print is a set of pretty print macros, useful for print-debugging.