Introduction to MetaPRL Debugging

First, before you start debugging your code, it may be a good idea to make sure you are using the "verbose" refiner.

In the process of debugging your code, you may end up adding some statements that print some debugging information or perform some sanity checks (and notify you if something went wrong). Usually you would want some way of temporarily enabling and disabling such debugging code. Of course, you can always comment it out when you do not need it and uncomment it back when you need it again. But instead of this playing with comments, please consider using the Mp_debug module.

Add the following to your code:

By default, the !debug_<name> would be false. There are several ways to make it true:

  1. By setting the MP_DEBUG environment variable in your shell before you start MetaPRL. MP_DEBUG should be a colon-separated list of names (without the debug_ prefix).
  2. By running the "set_debug "<name>" true" command from the MetaPRL toploop.
  3. By using debug_value = true instead of false in create_debug. Usually, it's not a good idea to do so, unless you want all MetaPRL users to participate in the debugging.
  4. By using debug_<name>:=true in your code. It is rarely a good idea, but here is an example when it may be a good idea to use it:
       if !debug_my_code then begin
          let save=!debug_other_code in
          other_code ();
       end else
          other_code () 
    Note that whoever wrote the other_code does not have to export debug_other_code in their .mli file - see Note 1.


  1. If you run create_debug more that once with the same debug_name (for example, in several modules or in several instances of the same module), you'll get the pointer to the same boolean. If you are sure that the debug with that name is already created, you can use a shorter load_debug "<name>" instead of create_debug { ... } to get a reference to that debug variable.
  2. If you are creating lots of debugging code, you may want to create several debug variables with different names to have finer control over what pieces of debugging code are active.

Debug variables

The following is the current list of debug variables currently defined in MetaPRL.