Previous week Up Next week

Hello

Here is the latest Caml Weekly News, for the week of 27 September to 04 October, 2005.

  1. Dynamic linking
  2. Looking for a configuration file library
  3. Russian Functional Programming Wiki
  4. caml_hash_variant()
  5. ocamlscript 1.1
  6. Perl-like Regexps implemented in Ocaml?
  7. Ray tracer language comparison

Dynamic linking

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30583

Continuing the thread from last week, Jacques Garrigue said:
Follow-up on dynamic linking for native code:

I believed this didn't exist for ocaml, but I just learned that
MetaOCaml does it, at least on x86.
So this is not only possible, but an implementation is available.
(I understand this is partly work in progress.)
    
Alexander Bottema added:
I managed to get dynamic linking for OCaml (i.e. making OCaml producing
DLLs that could then be used by other native code/binaries) to work on
almost all our supported platforms (Linux x86, Windows (2000/XP),
Solaris 2, Mac OS X).
The only platform which I couldn't get to work was Linux AMD64. I tried
to modify the OCaml emitter for AMD64 to accommodate position
independent code using the offset tables, but it was too hard. If anyone
picks up this task, please let us know. As it stands today we cannot use
OCaml for production code.
    

Looking for a configuration file library

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30612

David Mentre asked:
For easy configuration of my programs, I'm looking for some OCaml code
to read and write a user configuration file.

Currently, I have following requirements:

 - pure OCaml, without depencies on other libraries (I have enough
depencies in my program);

 - allows human readable and editable configuration files (i.e. no
XML), preferably structured;

 - (preferably) allows to easily load and save OCaml data structure,
like Hashtbl.

On the Hump, I found Config_file:
  http://caml.inria.fr/cgi-bin/hump.fr.cgi?contrib=335

Any other suggestion?
    
David Mentre asked and Maxence Guesdon answered:
> While browsing the debian packaging of Cameleon, I noticed that there
> is a liboptions-ocaml-dev for cameleon 1.3. Is it the same library
> that we are speaking about or a different one?
>  http://packages.debian.org/stable/libdevel/liboptions-ocaml-dev

The Config_file library was originally the Options library included in Cameleon.
Jean-Baptiste Rouquier made from Options an object-oriented library,
Config_file, which is also easier to use. 
In Cameleon2, the Options library has been replaced by the Config_file library.
So the Config_file library can be retrieved separately or with Cameleon2.
    

Russian Functional Programming Wiki

Archive: http://thread.gmane.org/gmane.comp.lang.ocaml.beginners/4226

Andrey Batyuk announced:
For whom it may concern I've started a new Wiki in russian regarding 
functional programming. This wiki will contain tranlations of general FP 
articles, language-specific articles et cetera.
Address is http://fp.batyuk.net
Everyone is welcomed to read and write there.
Also, if you know any useful articles that can be translated to russian 
for wide audience, please let me know.
    

caml_hash_variant()

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30641

Paul Argentoff asked and Jacques Garrigue answered:
> What caml_hash_variant() can be used for?

Well, what do you want to use it for?
It lets you retrieve the 31-bit representation used for a poymorphic
variant or method tag. This is useful if you want to access
polymorphic variants or objects from your C code.
Note that this hashing function is fixed, so depending on your
performence requirements you might want to compute the hashed values
before compilation, and completely drop the string representation.
    

ocamlscript 1.1

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30665

David Mentre announced:
I've just released version 1.1 of ocamlscript. Changes:

 - the temporary copy of the original script contains proper reference
   to original source so line number and script name is correct in case
   of error (suggestion of Mike Lin);

 - change license to a BSD-like one. Apparently Public Domain imposes
   restriction of Software redistribution on a different medium. The new
   license should allow to use the software for about any use.

The source can be found at:
 http://www.linux-france.org/~dmentre/code/ocamlscript-1.1.tar.gz

To know what ocamlscript is, see my original post:
 http://caml.inria.fr/pub/ml-archives/caml-list/2005/08/aacc3ed731893e25d53d8c97ff6941a0.fr.html
    
Martin Jambon asked and David Mentre answered:
> I think it's a great idea, but I have a couple of questions:
> - how do you specify more than one library (on my OS everything that 
> follows #!/path/to/ocamlscript is treated as only one argument)?

Yes, I have the same behavior on my system (Linux). But multiple
arguments are correctly interpreted (I just checked it).

The multiple arguments are seen as a single argument by ocamlscript
(i.e. the behaviour you observed) but, as the compilation command is
done through a Unix.system call, the underlying shell re-interprets
arguments through space separations.

> - could packages be loaded with ocamlfind so that we don't have to worry 
> about dependencies, -I flags and camlp4 libraries?

Well, this software is quite short (about 100 lines) and is more a
proof of concept than expected to solve all cases. In other words, I
don't plan to invest much time in it. But it is free software and
patches are welcome. 

> Personnally, I would really appreciate if could write a script is a style 
> like this:
> 
> ------------
> #!/usr/bin/ocamlscript
> # packs = micmatch_pcre lacaml lablgtk
> (* my program starts here, the first line which doesn't start with a # *)
> let _ = print_endline "Hello"
> ------------
> 
> or maybe more like that:
> 
> ------------
> #!/usr/bin/ocamlscript
> 
> (*! packs = micmatch_pcre lacaml lablgtk *)
> 
> (* only the first ocaml comment is parsed by ocamlscript, if there is no 
> code before and starts with ! *)
> 
> let _ = print_endline "Hello"
> ------------
    

Perl-like Regexps implemented in Ocaml?

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30568

Oliver Bandel asked and Jerome Vouillon answered:
> recently I read a security warning about perlre-library.
> 
> As there is a binding to this Library to OCaml (Markus Mottl's),
> this means: a security risk for applications which use this library.
> 
> Is there any Perl-like regexp-library written in OCaml?

I wrote a fairly powerful regular expression library some years ago.
You can find it on http://sourceforge.net/projects/libre/.
    
Gerd Stolpmann said and Jerome Vouillon answered:
> Very interesting, did not know this library exists. Are you still
> interested in developing it?

It's not a high priority at the moment, but I'm at least ready to fix
any reported bug.

> I like that it is the only regexp library around that gives direct
> access to the regexp constructors (i.e. Re.alt, Re.seq, etc.). And there
> are several parsers for regexp strings. One could, for example, easily
> build a camlp4 frontend for easier syntax.
> 
> You mention in TODO.txt that you also have a generic interface in mind.
> That would be really great. An application of that could be
> Unicode-capable regexp executor that directly operates on int arrays (as
> representation of Unicode strings). None of the other libraries has
> that.
> 
> And finally to mention, libre has a thread-safe API. Other people did
> not succeed in making one.

It is not quite thread-safe, actually, as it uses a mutable
datastructures internally (a DFA is built lazily).  Still, you can use
it simultaneously in different threads as long as no compiled regular
expression is used simultaneoously by several threads.

> To encourage the usage of your library, I'll immediately make a GODI
> package.

You should package the CVS version of the library.  It has several bug
fixed compare to version 0.1.
    

Ray tracer language comparison

Archive: http://thread.gmane.org/gmane.comp.lang.caml.general/30671

Jon Harrop announced:
I've updated my language comparison with four implementations in Scheme and 
one in Lisp:

  http://www.ffconsultancy.com/free/ray_tracer/languages.html

In short, Stalin's run-time performance is excellent (36% faster than 
ocamlopt) but its compile times are poor (2,000x slower than ocamlopt!) and 
SBCL-compiled Lisp is 6x slower than ocamlopt. Both Scheme and Lisp are >2x 
as verbose as OCaml.

Juho Snellman posted an interesting Lisp variant that used a macro to factor 
out unboxing, greatly reducing the stress on the GC and improving Lisp's 
performance to that of OCaml. Applying the same optimisation to the OCaml 
implementations makes them much faster again but I have yet to factor this 
out into a camlp4 macro.

This raises two interesting questions:

1. Can a camlp4 macro be written to factor out this unboxing transformation:

  let v = center -| orig in
  let b = dot v dir in
  let disc = b *. b -. dot v v +. radius *. radius in

where "+|" denotes vector addition and "*|" denotes scalar*vector 
multiplication. Transformed to:

  let vx = center.x -. orig.x in
  let vy = center.y -. orig.y in
  let vz = center.z -. orig.z in
  let b = vx *. dir.x +. vy *. dir.y +. vz *. dir.z in
  let vv = vx *. vx +. vy *. vy +. vz *. vz in
  let disc = b *. b -. vv +. radius *. radius in

So the intermediate vectors are not allocated and collected.

2. Manually inlining the code gives a huge performance improvement but using 
-inline does not appear to give this improvement. I assume ocamlopt can 
inline this but will not remove the boxing and subsequent unboxing. Is that 
right?
    

Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1
zM

If you know of a better way, please let me know.


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