Hello
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.
Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00009.html
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__ macros. For example, the following content, named test.ml: let test = __LOCATION__ When processed through 'camlp4o pa_macro.cmo', will result in: let test = Loc.of_tuple ("test.ml", 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 test.ml: module Loc = struct let of_tuple ((file_name, start_line, start_bol, start_off, stop_line, stop_bol, stop_off, is_ghost) as loc) = loc end let test = __LOCATION__ The source code (and some documentation in the head comment) for the "macro" camlp4 extension is in camlp4/Camlp4Parsers/Camlp4MacroParser.ml 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: http://bluestorm.info/camlp4//camlp4-doc/Sig.Loc.html 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: http://martin.jambon.free.fr/cppo.htmlMartin Jambon then added:
That's correct. Thanks for the plug. Here is an example: $ cat loc.ml #define loc (Printf.sprintf "File %S, line %i" __FILE__ __LINE__) print_endline loc;; print_endline loc;; $ ocamlopt -o loc -pp cppo loc.ml; ./loc File "loc.ml", line 3 File "loc.ml", line 4Anders 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 log. You may also be interested in the existing logging frameworks for OCaml, such as Bolt: http://bolt.x9c.fr/
Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00011.html
malc announced:New version of llpp (tagged v5) is now released, interested parties are free to grab it from http://repo.or.cz/w/llpp.git Blurb: llpp is a graphical less(1) like utility for viewing documents in Adobe PDF format. Help: Build instructions: http://repo.or.cz/w/llpp.git/blob/master:/BUILDING Keys to press: http://repo.or.cz/w/llpp.git/blob/master:/KEYS Changes: zoom in/out, panning, fit height, "presentation" mode, support for encrypted (password protected) documents, "real" scrollbar P.S. Caveat emptor http://bugs.ghostscript.com/show_bug.cgi?id=691629 (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 (http://repo.or.cz/w/dormin.git got) a face lift too: http://www.youtube.com/watch?v=68bqa5MAjTE http://www.youtube.com/watch?v=Ic2aTOaICtI
Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00012.html
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 LaTeX. 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 http://advi.inria.fr/ Mailing list and bug reports at advi AT inria.fr
Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00049.html
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 http://code.google.com/p/ocaml-extlib 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
Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00069.html
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 generator.ml, which can be found in http://okmij.org/ftp/continuations/caml-gen/ The file test_gen.ml 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 http://okmij.org/ftp/continuations/generators.html#ML for explanations and derivations of generators. Incidentally, the comments in generator.ml _derive_ the implementation.
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the recent posts from the ocamlcore planet blog at http://planet.ocamlcore.org/. Updated: MapListener example: http://gaiustech.wordpress.com/2011/08/08/updated-maplistener-example/ Haskell web development environment (on a mac): http://blog.dbpatterson.com/post/8557085769 OCaml binding for Coherence MapListener: http://gaiustech.wordpress.com/2011/08/06/ocaml-binding-for-coherence-maplistener/ sexplib: https://forge.ocamlcore.org/projects/sexplib/ Using types to track defaults: http://ocaml.janestcapital.com/?q=node/96
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.