caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] JIT VM in OCaml: Impossible?
Date: Thu, 16 Aug 2007 17:11:53 +0200	[thread overview]
Message-ID: <1187277113.46c469394ff4e@webmail.in-berlin.de> (raw)
In-Reply-To: <5C180944-2CD9-48FB-8802-8AF57972AD2C@gmail.com>

Zitat von Joel Reymont <joelr1@gmail.com>:

> Folks,
>
> Is it possible to write a JIT VM in OCaml?
>
> It seems that this should not be possible as OCaml does not allow for
> code generation at runtime. Am I mistaken?
[...]


It is possible to create functions on the fly
via putting together available functions by partial function application.

If you parse a "sin" in your code, you can use the "sin" form ocaml,
applying nor arguments to it. (Like passing function pointers in C,
but it's more elegant in functional languages, and more convenient.)

So it is possible to create applicable code.
I use this in one of my tools. There I create
certain comparison functions, for example, dependend
on what I parsed from my input.

I do this by creating closures (which means that
the functions that are the closures can be applied to
the arguments later).


A not perfect example (quick but not so dirty hacked, but possible
to make it better, as I just saw, when I answered your mail and
looked again in my *.mly, but maybe it can give you an idea
about what can be done, or how it could be done) is my tool
"apalogretrieve", which makes SQL-like queries on Apache
common logfiles:

  http://www.first.in-berlin.de/software/tools/apalogretrieve/

<disclaimer>
I know, it's not perfect (so, maybe the OCaml Gurus might
laugh about it) but it works for my needs and was done in
a short time, scattered about a long time.
</disclaimer>

Maybe it give's you an idea.

For a complete language to implement your stuff might
need more code, but if you have to implement a for-loop for example,
you could parse it from your language and create a
closure, which calls an OCaml for-loop directly (in the
closures).

You can make complex things by putting together partial applicated
functions. Look at how I create the conditions in the above mentioned code.

Ciao,
   Oliver

P.S.: Functional Programming should be written in this way:
      FUNctional programming, because it really makes FUN,
      at least to me. :)


  parent reply	other threads:[~2007-08-16 15:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 14:10 Joel Reymont
2007-08-16 14:37 ` Sylvain Le Gall
2007-08-16 15:32   ` [Caml-list] " Oliver Bandel
2007-08-16 15:56     ` Joel Reymont
2007-08-16 16:15   ` Jon Harrop
2007-08-16 15:11 ` Oliver Bandel [this message]
2007-08-16 16:24 ` [Caml-list] " Gordon Henriksen
2007-08-16 17:37   ` skaller
2007-08-16 18:05     ` Taras Glek
2007-08-17  2:50       ` skaller
2007-08-17  3:09         ` Erick Tryzelaar
2007-08-17  5:42           ` skaller
2007-08-17  7:52             ` Joel Reymont
2007-08-17  8:36               ` Jon Harrop
2007-08-17  9:20                 ` Joel Reymont
2007-08-17  8:39         ` Jon Harrop
2007-08-16 18:49   ` Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1187277113.46c469394ff4e@webmail.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).