Embedding OCaml within Python
bdesth.quelquechose at free.quelquepart.fr
Wed Apr 28 11:12:11 CEST 2004
Max Powers wrote:
> I've spent an interesting day searching the web for help with calling
> OCaml functions from a python program and have come to the newsgroup
> for some advice (unfortunately I'm learning both languages at the same
> time, so maybe I've missed something obvious!)
> The situation is this; I've got a large legacy program that is written
> in ocaml, within which there's a parser. I'd like to be able to call
> that parser from my python program (actually it's really a GUI using
> wxPython), rather than reimplement it (and then have to maintain two
> parsers into the future).
I may say something stupid but... I suppose this OCaml program has a CLI
? If so, can't you just call the OCaml program from your wxPython GUI
and get result back via a pipe ?
> I've come across Viper, which looks like a python compiler/interpreter
> implemented in OCaml, so I imagine that I could get it to do some
> magic tricks to call a ocaml library from python, but I think that's
> doomed to failure because of the C extensions of wxPython.
AFAIK, wxWidget is C++, not C...
> I've stumbled across Pycaml, but don't quite understand how to use it
> to call ocaml from python. Alternatively I think I can wrap the ocaml
> library in a C wrapper and then call that from python.
For what I saw (30' fast scan of the Pycaml page), it seems you would
need to write OCaml wrappers for your legacy OCaml code. But I dont have
any working experience in this kind of stuff, so I may have it all wrong.
> Can anyone give advice/share experiences? Is combining OCaml with
> python relatively straightforward with a bit more effort, or am I in
> for a world of pain?
I guess you could ask help from the OCaml community too...
Err... Not sure I'm really helpful here :(
More information about the Python-list