Version française
Home     About     Download     Resources     Contact us    
Browse thread
Metaprogramming features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jonathandeanharrop@g...>
Subject: Re: [Caml-list] Metaprogramming features
On Friday 03 October 2008 16:09:40 Dario Teixeira wrote:
> Hi,
>
> > I really wish that the basic features of metaocaml, namely
> > .< >., .~ and .! were included in OCaml proper.  The many other
> > experimental features of metaocaml could stay 'experimental',
> > those are the 3 which are sorely needed.
>
> To those of us not familiar with MetaOcaml, could you give us
> an overview of what these features mean and why they are so
> special?

MetaOCaml extends OCaml with three constructs that allow programs to generate, 
compile and evaluate code at run time.

Code is represented by the form:

  .< 1 + 2 >.

This may be executed using:

  .! .< 1 + 2 >.

Values may be injected into code using:

  .< 1 + .~x >.

This makes it vastly easier to turn term-level interpreters into compilers to 
obtain substantial performance improvements.

However, MetaOCaml has problems:

1. Obvious applications are low-level compilers for regular expressions, 
parsers and bytecodes but MetaOCaml imposes the limitations of OCaml (e.g. 
slow char and int handling) which makes it unsuitable for most such 
applications.

2. Non-trivial features in the target language can require great complexity, 
e.g. writing a compiler in MetaOCaml for a language with exceptions imposes 
CPS everywhere which is obfuscated and slow without language support.

3. You cannot generate new pattern matches to leverage OCaml's optimizing 
pattern match compiler in your run-time generated code (but you can use 
static ones).

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e