Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] adding a scripting language to an ocaml program

14 views
Skip to first unread message

Martin DeMello

unread,
Jul 3, 2010, 2:34:39 PM7/3/10
to OCaml List
Has much work been done on adding a scripting language to an OCaml
program? I googled about a bit, but no one seems to be even talking
about this - for example, if I wanted to do something emacslike with a
core in OCaml and (ideally) some sort of scheme as a scripting engine
in place of elisp, would that be easily doable?

martin

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Michael Ekstrand

unread,
Jul 3, 2010, 2:43:34 PM7/3/10
to caml...@inria.fr
On 07/03/2010 02:34 PM, Martin DeMello wrote:
> Has much work been done on adding a scripting language to an OCaml
> program? I googled about a bit, but no one seems to be even talking
> about this - for example, if I wanted to do something emacslike with a
> core in OCaml and (ideally) some sort of scheme as a scripting engine
> in place of elisp, would that be easily doable?

The authors of C-- have implemented a Lua engine in OCaml, with a good,
high-level, type-safe interface for embedding it. Look for 'lua-ml'.
There is also an OCaml implementation of Scheme called 'ocs'; I do not
have experience with it, so I cannot speak to its API style. Finally,
there are OCaml bindings to the SpiderMonkey JavaScript engine.

So, it has been done, and ocs is probably closest to what you're looking
for.

- Michael

Lukasz Stafiniak

unread,
Jul 3, 2010, 2:52:15 PM7/3/10
to Martin DeMello, OCaml List
By the way, there was once a project to rewrite Emacs in OCaml and use
OCaml instead of ELisp as its scripting language, but I can't even
google it now...

Vincent Aravantinos

unread,
Jul 3, 2010, 2:53:30 PM7/3/10
to Lukasz Stafiniak, OCaml List
At least there is roughly the same in Haskell :

http://www.haskell.org/haskellwiki/Yi

Le 3 juil. 10 à 20:52, Lukasz Stafiniak a écrit :

Martin DeMello

unread,
Jul 3, 2010, 2:56:40 PM7/3/10
to caml...@inria.fr
On Sun, Jul 4, 2010 at 12:13 AM, Michael Ekstrand <mic...@elehack.net> wrote:
> The authors of C-- have implemented a Lua engine in OCaml, with a good,
> high-level, type-safe interface for embedding it.  Look for 'lua-ml'.
> There is also an OCaml implementation of Scheme called 'ocs'; I do not
> have experience with it, so I cannot speak to its API style.  Finally,
> there are OCaml bindings to the SpiderMonkey JavaScript engine.

Both lua-ml and ocs seem dead (their homepages are gone) :( Can't tell
if spidercaml is active or not; the page has a download link for
version 0.2 and no date.

martin

Martin DeMello

unread,
Jul 3, 2010, 3:02:38 PM7/3/10
to Lukasz Stafiniak, OCaml List
On Sun, Jul 4, 2010 at 12:22 AM, Lukasz Stafiniak <luks...@gmail.com> wrote:
> By the way, there was once a project to rewrite Emacs in OCaml and use
> OCaml instead of ELisp as its scripting language, but I can't even
> google it now...

Chamo? I looked at it but they seem to be using gtksourceview as an
editor so it wouldn't work on a console. I actually want to write a
vim clone; I love vim but I can't stand vimscript and the other
languages it supports all seem distinctly second-class. I think a good
modal editor with an emacs architecture where as much as possible is
written in the "soft" layer would be a very nice thing to have.

Martin DeMello

unread,
Jul 3, 2010, 3:05:39 PM7/3/10
to Vincent Aravantinos, OCaml List
On Sun, Jul 4, 2010 at 12:23 AM, Vincent Aravantinos
<vincent.a...@gmail.com> wrote:
> At least there is roughly the same in Haskell :
> http://www.haskell.org/haskellwiki/Yi

Yeah :) My other option is to just learn enough Haskell and join Yi,
rather than trying to reinvent the wheel. I do think scheme would be a
nicer extension language than either Haskell (Yi) or Lua (yzis),
though.

Michael Ekstrand

unread,
Jul 3, 2010, 3:07:03 PM7/3/10
to caml...@inria.fr
On 07/03/2010 02:56 PM, Martin DeMello wrote:
> On Sun, Jul 4, 2010 at 12:13 AM, Michael Ekstrand <mic...@elehack.net> wrote:
>> The authors of C-- have implemented a Lua engine in OCaml, with a good,
>> high-level, type-safe interface for embedding it. Look for 'lua-ml'.
>> There is also an OCaml implementation of Scheme called 'ocs'; I do not
>> have experience with it, so I cannot speak to its API style. Finally,
>> there are OCaml bindings to the SpiderMonkey JavaScript engine.
>
> Both lua-ml and ocs seem dead (their homepages are gone) :( Can't tell
> if spidercaml is active or not; the page has a download link for
> version 0.2 and no date.

For lua-ml this is a new development. The site was there within the
last few months, albeit with the last release some years ago (2007 or
so, I believe). The domain must have lapsed.

On OCS, it looks like a temporary failure from here. I do not know what
its development status is; it was a fairly young project last I looked
at it, IIRC.

- Michael

David Powers

unread,
Jul 3, 2010, 3:16:40 PM7/3/10
to caml...@yquem.inria.fr
I did this for entertainment a few months ago. I make no promises about its
utility for any purpose. ;)

http://bitbucket.org/dpowers/luacaml

David Allsopp

unread,
Jul 3, 2010, 3:35:43 PM7/3/10
to Martin DeMello, caml...@inria.fr
Martin DeMello wrote:
> On Sun, Jul 4, 2010 at 12:13 AM, Michael Ekstrand <mic...@elehack.net>
> wrote:
> > The authors of C-- have implemented a Lua engine in OCaml, with a
> > good, high-level, type-safe interface for embedding it.  Look for 'lua-
> ml'.
> > There is also an OCaml implementation of Scheme called 'ocs'; I do not
> > have experience with it, so I cannot speak to its API style.  Finally,
> > there are OCaml bindings to the SpiderMonkey JavaScript engine.
>
> Both lua-ml and ocs seem dead (their homepages are gone) :(

> Can't tell if spidercaml is active or not; the page has a download link for
> version 0.2 and no date.

SpiderCaml is alive and well - I submitted patches (which are in SVN) to Alain a few months ago for 0.2 but I don't think he's time to wrap it all into another release. I haven't tested against Mozilla's latest offering but I have it working very nicely with SpiderMonkey 1.7.0 on Windows 7. It's only because compiling MinGW builds of SpiderMonkey is non-trivial that I haven't tried it against the a 1.8 engine - on Linux (or possibly using the MSVC Windows branch) I expect it would be easy to do.


David

malc

unread,
Jul 3, 2010, 4:43:25 PM7/3/10
to Lukasz Stafiniak, OCaml List
On Sat, 3 Jul 2010, Lukasz Stafiniak wrote:

> By the way, there was once a project to rewrite Emacs in OCaml and use
> OCaml instead of ELisp as its scripting language, but I can't even
> google it now...

http://pauillac.inria.fr/cdrom_a_graver/prog/unix/efuns/eng.htm

[..snip..]

--
mailto:av1...@comtv.ru

Martin DeMello

unread,
Jul 3, 2010, 5:15:48 PM7/3/10
to Philippe Wang, OCaml List
On Sun, Jul 4, 2010 at 2:29 AM, Philippe Wang <ma...@philippewang.info> wrote:
>
> Here another reference:
> "Efuns is a small text editor, entirely written in Objective-Caml."
> http://pauillac.inria.fr/cdrom_a_graver/prog/unix/efuns/eng.htm
> but it's kind of old...

Thanks, looks interesting. Even if it's old, I can get a lot of nice
ideas from the code.

Goswin von Brederlow

unread,
Jul 4, 2010, 3:54:38 PM7/4/10
to Martin DeMello, OCaml List
Martin DeMello <martin...@gmail.com> writes:

> Has much work been done on adding a scripting language to an OCaml
> program? I googled about a bit, but no one seems to be even talking
> about this - for example, if I wanted to do something emacslike with a
> core in OCaml and (ideally) some sort of scheme as a scripting engine
> in place of elisp, would that be easily doable?
>
> martin

Yes. In bytecode you can run an ocaml toplevel and use ocaml as
scripting lanugage. Or you can implement a scheme interpreter quite
easily in ocaml. It is a verry simple language.

MfG
Goswin

Florent Monnier

unread,
Jul 5, 2010, 8:24:11 AM7/5/10
to caml...@yquem.inria.fr
Le dimanche 4 juillet 2010 21:54:31, Goswin von Brederlow a écrit :
> Martin DeMello <martin...@gmail.com> writes:
> > Has much work been done on adding a scripting language to an OCaml
> > program? I googled about a bit, but no one seems to be even talking
> > about this - for example, if I wanted to do something emacslike with a
> > core in OCaml and (ideally) some sort of scheme as a scripting engine
> > in place of elisp, would that be easily doable?
> >
> > martin
>
> Yes. In bytecode you can run an ocaml toplevel and use ocaml as
> scripting lanugage. Or you can implement a scheme interpreter quite
> easily in ocaml. It is a verry simple language.

there is schoca:

http://community.schemewiki.org/?Schoca
http://sourceforge.net/projects/chesslib/

I don't know if it's worth, I only know its name

--
cheers

Thomas Fischbacher

unread,
Jul 5, 2010, 9:33:47 AM7/5/10
to Martin DeMello, OCaml List

Martin DeMello asked:

> Has much work been done on adding a scripting language to an OCaml
> program? I googled about a bit, but no one seems to be even talking
> about this - for example, if I wanted to do something emacslike with a
> core in OCaml and (ideally) some sort of scheme as a scripting engine
> in place of elisp, would that be easily doable?

We (the nmag/nsim dev team - http://nmag.soton.ac.uk) kind-of had the
opposite problem, i.e. we had to extend a scripting language that is
easy to learn with something that has a bit more steam. We decided to
use Python+OCaml. There's a semi-abandoned debian package, pycaml,
that does this, but that's broken - it has memory management bugs
both oh the Python and OCaml side. Here is a fixed version that also
supports a few nice extensions:

http://nmag.soton.ac.uk/tf/pycaml/

I should say that being able to extend Python with fast code without
having to worry about allocating/destroying things and having the
convenience of simple callbacks both ways is a very nice thing.

--
best regards,
Thomas Fischbacher
t.fisc...@soton.ac.uk

Mehdi Dogguy

unread,
Jul 5, 2010, 12:13:44 PM7/5/10
to Thomas Fischbacher, OCaml List
On 05/07/2010 15:14, Thomas Fischbacher wrote:
>
> We (the nmag/nsim dev team - http://nmag.soton.ac.uk) kind-of had the
> opposite problem, i.e. we had to extend a scripting language that is
> easy to learn with something that has a bit more steam. We decided to
> use Python+OCaml. There's a semi-abandoned debian package, pycaml, that
> does this, but that's broken - it has memory management bugs both oh
> the Python and OCaml side.

uh… did you try to submit patches or report bugs against the package?

pycaml is known to be dead upstream. We¹ do our best to keep it in a good
shape. But, we don't receive bugreports against pycaml and is used
by only one package… that makes bug fixing not easy :)

> Here is a fixed version that also supports a few nice extensions:
>
> http://nmag.soton.ac.uk/tf/pycaml/
>

Is this released/linked/advertised somewhere? (other than this mail).
It would be nice to have your fixes packages so that others can benefit
from your work.

¹: I'm not aware of any pycaml user among Debian OCaml Maintainers.

Regards,

--
Mehdi Dogguy مهدي الدڤي
http://www.pps.jussieu.fr/~dogguy
Tel.: (+33).1.44.27.28.38

Thomas Fischbacher

unread,
Jul 5, 2010, 12:56:37 PM7/5/10
to Mehdi Dogguy, OCaml List

Mehdi Dogguy wrote:

>> We (the nmag/nsim dev team - http://nmag.soton.ac.uk) kind-of had the
>> opposite problem, i.e. we had to extend a scripting language that is
>> easy to learn with something that has a bit more steam. We decided to
>> use Python+OCaml. There's a semi-abandoned debian package, pycaml, that
>> does this, but that's broken - it has memory management bugs both oh
>> the Python and OCaml side.
>
> uh… did you try to submit patches or report bugs against the package?

Yes. We did have some discussion about these things with the debian
ocaml maintainers quite a long time ago - but somehow our fixes never
were incorporated into the package.

Part of the problem is that the original pycaml package is fairly
awkward code no one is too proud of. But still, it works (at least
our fixed and extended version does), and it actually is quite useful.

The last thing I remember is that Guillaume had contacted me about
wanting to re-write it, but not much seems to have happened on that
front so far. I'd strongly suggest we just stick our heads together
and get our code into the debian package so that at least the serious
memory corruption problems are fixed. People might not exactly have
much fun starting to use it only to experience rude mm-related
surprises.

I think our pycaml patches were first mentioned here:

http://caml.inria.fr/pub/ml-archives/caml-list/2007/11/7a1c5726ab3d6661c233a7245fc6cca8.en.html

> pycaml is known to be dead upstream. We¹ do our best to keep it in a good
> shape. But, we don't receive bugreports against pycaml and is used
> by only one package… that makes bug fixing not easy :)
>
>> Here is a fixed version that also supports a few nice extensions:
>>
>> http://nmag.soton.ac.uk/tf/pycaml/
>>
>
> Is this released/linked/advertised somewhere? (other than this mail).
> It would be nice to have your fixes packages so that others can benefit
> from your work.

Replacing the code in the debian package with ours is quite
straightforward.

--
best regards,
Thomas Fischbacher
t.fisc...@soton.ac.uk

_______________________________________________

Mehdi Dogguy

unread,
Jul 5, 2010, 2:04:30 PM7/5/10
to Thomas Fischbacher, OCaml List
On 07/05/2010 06:30 PM, Thomas Fischbacher wrote:
>
> Yes. We did have some discussion about these things with the debian
> ocaml maintainers quite a long time ago - but somehow our fixes never
> were incorporated into the package.
>

The only discussion I've found is:

http://lists.debian.org/debian-ocaml-maint/2007/11/msg00158.html

>
> Replacing the code in the debian package with ours is quite
> straightforward.
>

… if the interface is "compatible" (I didn't really check). I had a
quick look and noticed some changes for some type definitions. Did you
try to compile coccinelle¹ using your version of pycaml for example?
It's the single package using the pycaml library we have in our
archive. If it requires some changes, we'd prefer to get them integrated
by coccinelle's upstream before shipping the new pycaml.

¹: http://coccinelle.lip6.fr/

Besides, having a version and listable directory with available versions
of pycaml would help to get the code packaged and integrated. Would you
accept to maintain it on forge.ocamlcore.org? We can provide you a
D?$VCS, a bugtracker, etc… there. If yes, please fill the form available at:

https://forge.ocamlcore.org/register/projectinfo.php

Regards,

--
Mehdi Dogguy مهدي الدڤي
http://www.pps.jussieu.fr/~dogguy
Tel.: (+33).1.44.27.28.38

_______________________________________________

Richard Jones

unread,
Jul 6, 2010, 6:39:00 AM7/6/10
to Martin DeMello, OCaml List
On Sun, Jul 04, 2010 at 12:04:32AM +0530, Martin DeMello wrote:
> Has much work been done on adding a scripting language to an OCaml
> program? I googled about a bit, but no one seems to be even talking
> about this - for example, if I wanted to do something emacslike with a
> core in OCaml and (ideally) some sort of scheme as a scripting engine
> in place of elisp, would that be easily doable?

You can embed a Perl interpreter and call out to Perl code using
perl4caml's Perl.eval function. The API is even "type safe" in as
much as you can construct and examine the values going between the
Perl and the OCaml code, and detect errors at runtime (at compile time
too in some circumstances).

http://git.annexia.org/?p=perl4caml.git;a=blob;f=perl.mli;h=64d7904eb633bcc410f796d19e289bca49931bb5;hb=HEAD#l258

Your users might not thank you for this ...

Rich.

--
Richard Jones
Red Hat

Martin DeMello

unread,
Jul 6, 2010, 8:55:26 AM7/6/10
to Richard Jones, OCaml List
On Tue, Jul 6, 2010 at 4:08 PM, Richard Jones <ri...@annexia.org> wrote:
>
> You can embed a Perl interpreter and call out to Perl code using
> perl4caml's Perl.eval function.  The API is even "type safe" in as
> much as you can construct and examine the values going between the
> Perl and the OCaml code, and detect errors at runtime (at compile time
> too in some circumstances).
>
> http://git.annexia.org/?p=perl4caml.git;a=blob;f=perl.mli;h=64d7904eb633bcc410f796d19e289bca49931bb5;hb=HEAD#l258
>
> Your users might not thank you for this ...

Probably not :) My primary concern is that the editor won't be snappy
enough - Yi definitely has that problem, for instance - which is why I
was hoping for a scripting language that people were using and
optimising for speed.

martin

Guillaume Yziquel

unread,
Jul 6, 2010, 5:07:44 PM7/6/10
to Thomas Fischbacher, Mehdi Dogguy, OCaml List
Thomas Fischbacher a écrit :

>
> The last thing I remember is that Guillaume had contacted me about
> wanting to re-write it, but not much seems to have happened on that
> front so far.

Well, things have happened on this front so far. And a few people have
the code that I've written. Unfortunately, for rather awkward reasons, I
am not in a position to release it. But hope to be in the rather not
distant future.

It's basically a rewrite. It works, but isn't fully featured yet. I
believe memory management is done properly. There are also some C
varargs functions in the Python API that have been properly binded with
the libavr library (or something called like that). A (yet basic) syntax
extension allows to write things like:

module X = python module mypython module

It does introspection and dumps the OCaml code needed to access values
of the module. I've been hitting type inference issues in Python for
this. But there is some work (like shedskin) to capitalise in order to
make the syntax extension more interesting when it comes to typing.

And there's a Debian package, also.

Do not hold your breath on this code, as a release might take a while.

But if someone is willing to carve out of shedskin the code needed to do
type inference and bind it to OCaml, that would be a nice contribution
to the syntax extension.

I do not have much time available on this one, and I currently have
other interests. But if someone is interested in the code, please email
me to see what is possible to do...

All the best,

Guillaume Yziquel.
--
Guillaume Yziquel
http://yziquel.homelinux.org/

Guillaume Yziquel

unread,
Jul 6, 2010, 5:14:16 PM7/6/10
to Thomas Fischbacher, Mehdi Dogguy, caml-list List
Guillaume Yziquel a écrit :

>
> I do not have much time available on this one, and I currently have
> other interests. But if someone is interested in the code, please email
> me to see what is possible to do...

I mean: privately.

All the best,

Thomas Fischbacher

unread,
Jul 8, 2010, 11:23:21 AM7/8/10
to Mehdi Dogguy, OCaml List

Mehdi Dogguy wrote:

> http://lists.debian.org/debian-ocaml-maint/2007/11/msg00158.html
>
>> Replacing the code in the debian package with ours is quite
>> straightforward.

Well... I just updated the directory at:

http://www.soton.ac.uk/~doctom/software/pycaml-patched/

When I debuild -us -uc the lot, this produces a working package
on my machine.

> … if the interface is "compatible" (I didn't really check).

I think so. Basically, I removed one function which never had worked
anyway and added a number of new ones.

> I had a
> quick look and noticed some changes for some type definitions. Did you
> try to compile coccinelle¹ using your version of pycaml for example?

I just gave it a try - please take a look at the log at:

http://www.soton.ac.uk/~doctom/software/coccinelle.log

> It's the single package using the pycaml library we have in our
> archive. If it requires some changes, we'd prefer to get them integrated
> by coccinelle's upstream before shipping the new pycaml.
>
> ¹: http://coccinelle.lip6.fr/
>
> Besides, having a version and listable directory with available versions
> of pycaml would help to get the code packaged and integrated. Would you
> accept to maintain it on forge.ocamlcore.org? We can provide you a
> D?$VCS, a bugtracker, etc… there. If yes, please fill the form available at:
>
> https://forge.ocamlcore.org/register/projectinfo.php

Yes, we could (and should) do that.

I'm just waiting for the account registration confirmation email.

--
best regards,
Thomas Fischbacher
t.fisc...@soton.ac.uk

_______________________________________________

Mehdi Dogguy

unread,
Jul 8, 2010, 12:00:17 PM7/8/10
to Thomas Fischbacher, OCaml List
On 08/07/2010 17:22, Thomas Fischbacher wrote:
>> … if the interface is "compatible" (I didn't really check).
>
> I think so. Basically, I removed one function which never had worked
> anyway and added a number of new ones.
>

Good.

>> I had a quick look and noticed some changes for some type
>> definitions. Did you try to compile coccinelle¹ using your version
>> of pycaml for example?
>
> I just gave it a try - please take a look at the log at:
>
> http://www.soton.ac.uk/~doctom/software/coccinelle.log
>

Looks fine.

>> https://forge.ocamlcore.org/register/projectinfo.php
>
> Yes, we could (and should) do that.
>
> I'm just waiting for the account registration confirmation email.
>

Perfect! As soon as the project is up (with a D?$VCS, a version and
versioned tarball), I'll package it and upload it in our archive.

Thanks!

--
Mehdi Dogguy مهدي الدڤي
http://www.pps.jussieu.fr/~dogguy
Tel.: (+33).1.44.27.28.38

_______________________________________________

0 new messages