Previous week Up Next week


Here is the latest Caml Weekly News, for the week of August 02 to 09, 2011.

There won't be a CWN next week as I'm moving.

  1. filename and line number
  2. llpp v5
  3. New release 1.10.0 of Active-DVI
  4. extlib 1.5.2 released
  5. Generators in OCaml
  6. Other Caml News

filename and line number


Anders Fugmann asked and Gabriel Scherer replied:
> Do there exist a way to get filename and linenumber of the calling function
> - Or at least the of the current filename and line number?
> I guess this would involve a syntax camlp4 syntax extension, but I'm not a
> camlp4 wizard and google did not come up with any suggestions.

There is a "macro" syntax extension that is distributed with Camlp4,
and can do basic cpp-like stuff, including __FILE__ and a __LOCATION__

For example, the following content, named

  let test =

When processed through 'camlp4o pa_macro.cmo', will result in:

  let test = Loc.of_tuple ("", 2, 13, 17, 2, 13, 29, false)

(To compile:  ocamlc -pp 'camlp4o pa_macro.cmo' ...)

The "Loc.of_tuple" call is a reference to a function implemented in
Camlp4 Loc module; if you make you project depend (at runtime, not
camlp4-time) on Camlp4 loc-handling libraries, you'll get functions to
manipulate the location and its information. You can also define your
own Loc module in

  module Loc = struct
    let of_tuple
      ((file_name, start_line, start_bol, start_off, stop_line,
stop_bol, stop_off, is_ghost) as loc) =

  let test =

The source code (and some documentation in the head comment) for the
"macro" camlp4 extension is in
camlp4/Camlp4Parsers/ in the ocaml source tree.

The meaning of the weird tuple arguments can be found in the Camlp4
documentation. I have a not exactly up-to-date (I guess ocaml 3.11)
version of the documentation on my website, see:

Finally, Martin Jambon also has its own "cppo" tools mimicking cpp,
which I suppose doesn't rely on camlp4, and has __FILE__ and __LINE__
macros which may be in a more directly exploitable format. I have
never tried it though. See:
Martin Jambon then added:
That's correct. Thanks for the plug.

Here is an example:

$ cat
#define loc (Printf.sprintf "File %S, line %i" __FILE__ __LINE__)

print_endline loc;;
print_endline loc;;

$ ocamlopt -o loc -pp cppo; ./loc
File "", line 3
File "", line 4
Anders Fugmann then asked and Gabriel Scherer replied:
> Using cppo, would I need to define 'loc' in each file using log, or can it
> be defined in another module?
> If not, I guess the alternative is to create a syntax extenstion that will
> include Loc.t structure as a parameter to some print function - or add it
> manually, but I would like to avoid cluttering the code with __LOCATION__
> everywhere.

Both pa_macros and cppo have a file-inclusion directive, so you could
define your preferred location-reporting macro in a header file.
That said, I would personally use the __LOCATION__ macro directly: the
less preprocessing stuff the better, and if it "clutters your code"
you could restrict your reporting a bit, which may not be a bad thing:
having a log full of useless stuff is only a bit better than having no

You may also be interested in the existing logging frameworks for
OCaml, such as Bolt:

llpp v5


malc announced:
New version of llpp (tagged v5) is now released, interested parties are
free to grab it from

llpp is a graphical less(1) like utility for viewing documents in Adobe
PDF format.

Build instructions:
Keys to press:

zoom in/out, panning, fit height, "presentation" mode, support for
encrypted (password protected) documents, "real" scrollbar

P.S. Caveat emptor
     (i.e. one might want to use version of mupdf before it fixed
      one issue by replacing it with another (perhaps more severe one))

P.P.S. dormin ( got) a face lift too:

New release 1.10.0 of Active-DVI


Didier Remy announced:
Version 1.10.0 of Active-DVI is available.

Active-DVI is a presenter and previewer for texts or slides written in

It can display files in DVI format and is thus a possible replacement for
other DVI previewers.

It also commes with a package advi.sty that provided macros and generate
new DVI-specials understood by Active-DVI that enables:

   * Image file inclusions in a variety of different formats

   * Some effects for presentation: pause, delay,  background images,
     transitions, etc.

   * Embedded applications.

   * Special Support for WhizzyTeX including

      - Following the cursor, as you type.
      - Backpointing to the source file.
      - (Rudimentary) support for moving or resizing objects with the mouse.

   * Supports the pgf package and the beamer document class.

This release is mostly for maintainance.
It requires the new version 4.0 of camlimages.

Play advi on the demonstration presentation demo.dvi that is in the test
directory of the distribution. Look at source code of the various talks in
the directory ``examples''.

The source code and more information are available at

Mailing list and bug reports at 
advi AT

extlib 1.5.2 released


ygrek announced:
It is my great pleasure to announce new bugfix release of extlib -
small and comprehensive extension for OCaml standard library.

Get it at

Release notes for extlib-1.5.2 (2011-08-06) :

* Bug fixes / improvements: 
 * memory corruption in DynArray.insert 
 * ExtList.make is now tail-recursive 
 * stack overflow in ExtString.nsplit 
 * ExtList.(@) is now in scope after open ExtLib 
 * DynArray will not attempt to grow past Sys.max_array_length 
 * faster ExtString.starts_with and ExtString.ends_with 
 * some documentation comments 
* New functions: 
 * List.find_map

Generators in OCaml


oleg announced:
The announced small library of generators in OCaml lets us write
generators like those in Python 2 -- as well as generators that go
beyond Python.  The library is a simple overlay over the library
delimcc of delimited continuations in OCaml. The library delimcc is
the only dependency of the generator library.

The library offers three primitives: yield, msplit, and new_prompt.
Prompts, created by new_prompt, are like loop labels in Perl.  The
yield expression delivers its value to any enumerator in scope, not
necessarily the innermost one. One might be surprised at the absence
of enumerators among the primitives. Enumerators are programmed-in;
the library does provide a few popular enumerators such as
for_loop. Users may write enumerators of their own, like for-loop-while
or for-loop-upto, etc. The sample code shows examples of custom
enumerators (including zipWith for parallel loops).  The library also
provides a few generators, such as the analogue of Icon's find -- so
that we can write the examples from Icon's tutorial.

Generator expressions are _expressions_: they may return a value, in
addition to yielding intermediate results. A good example is the
traversal of a binary tree post-order yielding the running sum of
labels of tree branches. Here is the complete code.

type label = int
type tree = Leaf | Node of label * tree * tree;;

let pint = new_prompt ()

let rec post_order = function
  | Leaf -> 0
  | Node (label, left, right) ->
      let sum_left  = post_order left in
      let sum_right = post_order right in
      let sum = sum_left + sum_right + label in
      yield pint sum; sum

for_loop pint (fun () -> Printf.printf "Final: %d\n" (post_order tree1))
   (fun x -> Printf.printf "Got %d\n" x)

Our generators can run side-by-side, hence supporting not only nested
loops but also parallel loops.

The library is simple, consisting of generator.mli and,
which can be found in

The file has several tests, including tests from Icon's
tutorial. The Makefile tells how to compile the tests as a stand-alone
executable (bytecode or native).

Please see

for explanations and derivations of generators. Incidentally, the
comments in _derive_ the implementation.

Other Caml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the
recent posts from the ocamlcore planet blog at

Updated: MapListener example:

Haskell web development environment (on a mac):

OCaml binding for Coherence MapListener:


Using types to track defaults:

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.

Alan Schmitt