Printing to the terminal for debugging

If you want to print output to the terminal, for now you can use debugPrint() along with debug_show():

let a: Nat = 10;
debugPrint(debug_show(a));

This outputs to the terminal that’s running dfx start (note this might be a separate window if you’re not using the --background flag).

6 Likes

Thanks for sharing the Syntax Ori. :ok_hand:

2 Likes

good hint! did anyone actually make the
print function work?

1 Like

yep it works. Have a look on the repo i posted yesterday, there are a few debug prints in it.

1 Like

print() alone isn’t working at the moment, it’s been reported to the team.

If you take a look in Guillaume’s repo you’ll see there are type-specific debug prints like debugPrintNat() too.

Another option is importing prelude and using printLn() (which calls debugPrint internally).

1 Like

I was about to make a post on this but you beat me to it Ori! Nice syntax alternative for those looking to use a similar print functionality.

3 Likes

Please note debugPrint has been moved from the default scope and now requires an import:

import Prim “mo:prim”;

let a: Nat = 10;
Prim.debugPrint(debug_show(a));
1 Like

did you actually manage to import mo:Prim ? didn’t work for me somehow :face_with_monocle:

1 Like

Lower case p in mo:prim?

1 Like

the problem was that i used import Prim „mo:prim.mo“ instead of import Prim „mo:prim“. that error is kind of weird because all other imports i use have the .mo suffix and work like a charm? is this because prim is not part of the stdlib? @claudio

2 Likes

So re this, the .mo extensions in imports will possibly be removed in the next version.

2 Likes

Updating this for recent releases:

import Debug “mo:base/Debug”;

let a: Nat = 10;
Debug.print(debug_show(a));
1 Like