OCaml syntax extension for simple logging in OCaml.
Source code: pa_log.ml (v1.2, Dec 2007)
This syntax extension provides simple logging with per-module conditional output for OCaml. Extending the syntax allows us to provide "lazy" evaluation of debug statements. Because of strict evaluation, functions like
let log_if p s = if p then print_string s else ()are forced to evaluate their arguments when p is false. Typically, when logging is turned off, we would like to avoid evaluating logging statements as much as possible.
_SET_DEBUG_LEVEL Module k : sets the debug level in
Module to k (an
int). Default is -1.
_DEBUG_LEVEL Module: the debug level (an
int) in Module.
_DEBUG k format arg1 ... argN : if k
>= the current module-specific debug level, passes the remaining
arguments to Format.printf or a
Format.printf-like function specified by
-dprintf FUN_EXPR
_LOG format arg1 ... argN : passes its arguments to
Format.printf or a Format.printf-like
function specified by -lprintf FUN_EXPR
-dprintf FUN_EXPR : use FUN_EXPR as
the debug logging printer. FUN_EXPR should be an OCaml
expression with type ('a, formatter, unit) format ->
'a (i.e., the same as Format.printf).
-lprintf FUN_EXPR : use FUN_EXPR as
the logging printer. FUN_EXPR should be an OCaml
expression with type ('a, formatter, unit) format ->
'a (i.e., the same as Format.printf).
Statically prevent logging code from appearing in the executable. _DEBUG will generate a dynamic check on the debug level. Using this extension will have a (probably negligible) effect on running time and code size, even with logging turned off.
Compile with:
ocamlc -o pa_log.cmo -pp "camlp4o pa_extend.cmo q_MLast.cmo -loc _loc" -I +camlp4 -c pa_log.ml
Use with:
ocamlc -pp "camlp4o pa_extend.cmo -I /usr/lib/ocaml str.cma ./pa_log.cmo -loc _loc" -I +camlp4 ML_FILE
This is an add-on to the standard Pa_macro syntax extension which
allows for command-line arguments of the form
-DEFuid=expr where uid is an
upper-case identifier (a macro name) and expr is an arbitrary
OCaml expression.
Source code: pa_macro_arg.ml (released March 2007)
Compile with:
ocamlc -o pa_macro_arg.cmo -pp "camlp4o pa_extend.cmo q_MLast.cmo -loc _loc" -I +camlp4 -c pa_macro_arg.ml
Use with:
ocamlc -pp "camlp4o pa_extend.cmo pa_macro.cmo ./pa_macro_arg.cmo -loc _loc" -I +camlp4 ML_FILE
NOTE: arguments will be interpreted by the shell before being passed to camlp4. Typical usage might look like:
"-DEF X=\"a\"" -DEF 'Y="b"' -DEFZ=\"c\" # X, Y, and Z have type string
-DEF FOO=1.0 # FOO has type float
I have an obsessive-compulsive problem with the default
formatting of LNCS papers on letter or A4 paper: the font is too large
and the margins are too wide. This Bash script takes an LNCS-formatted
Postscript or PDF file and generates a 2-per-page formatted Postscript
file, using acroread (for PDF inputs) and
pstops. The settings are what works on my system: the
pstops arguments will probably have to be tweaked on a
per-site basis. See this blog post for more information.
Source code: lncs2up.sh (released April 2008)
–Christopher Conway (cconway at cs dot nyu dot edu)
Last updated: 8 Jun 2008