caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Calling Ocaml from Python
@ 2004-04-29  7:42 Max Powers
  0 siblings, 0 replies; 11+ messages in thread
From: Max Powers @ 2004-04-29  7:42 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

On Thu, 2004-04-29 at 16:56, skaller wrote:
>On Thu, 2004-04-29 at 15:58, Max Powers wrote:
>
> > So as I see it I've got the following options:
> > 1) write the parser in ocaml. Wrap ocaml in C then wrap that using SWIG 
>into
> > a python module.
> > 2) write the parser in C. Use SWIG to generate Ocaml and python modules.
> > 3) write the parser in python. Use Pycaml to call the python module from
> > Ocaml.
>
>Ocaml is well suited to parsing and analysing
>the parsed terms. If you head for (2) or (3) one needs
>to ask why bother using Ocaml at all?

Ah, that's 'cause I've got a huge application written (by others, I'm just 
the GUI bunny) in Ocaml. They're not real happy with the current parser 
(it's kind of crufty I believe), so would be happy to replace it, so long as 
the data is available in the Ocaml world. Parsing config files isn't the 
apps main job :).

-Max

_________________________________________________________________
Personalise your phone with chart ringtones and polyphonics. Go to  
http://ringtones.com.au/ninemsn/control?page=/ninemsn/main.jsp

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
@ 2004-04-30  1:13 Max Powers
  0 siblings, 0 replies; 11+ messages in thread
From: Max Powers @ 2004-04-30  1:13 UTC (permalink / raw)
  To: caml-list

On Thu, 29 Apr 2004 16:24, art yerkes wrote:
>
> > >You can write a C wrapper for an Ocaml function in C,
> > >and then wrap THAT using SWIG so you can call it from Python.
>
>You might try pycaml: http://pycaml.sf.net/

In my original message I mentioned that I'd looked at pycaml, but I (sort 
of) understand how to call python from Ocaml from the example, but I don't 
understand how to use Pycaml to call Ocaml from python. Is there an example 
somewhere of this?

(sorry, my ocaml experience is very limited, my python's a bit better!)

Cheers,
-Max

_________________________________________________________________
Find love today with ninemsn personals. Click here:  
http://ninemsn.match.com?referrer=hotmailtagline

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  5:58 Max Powers
  2004-04-29  6:56 ` skaller
@ 2004-04-29 21:24 ` art yerkes
  1 sibling, 0 replies; 11+ messages in thread
From: art yerkes @ 2004-04-29 21:24 UTC (permalink / raw)
  To: Max Powers; +Cc: skaller, caml-list

> >You can write a C wrapper for an Ocaml function in C,
> >and then wrap THAT using SWIG so you can call it from Python.

You might try pycaml: http://pycaml.sf.net/
-- 
Hey, Adam Smith, keep your invisible hands to yourself!

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  3:09 Max Powers
  2004-04-29  3:49 ` skaller
  2004-04-29  5:45 ` Basile STARYNKEVITCH
@ 2004-04-29 14:16 ` John Goerzen
  2 siblings, 0 replies; 11+ messages in thread
From: John Goerzen @ 2004-04-29 14:16 UTC (permalink / raw)
  To: Max Powers; +Cc: caml-list

On Thu, Apr 29, 2004 at 12:39:24PM +0930, Max Powers wrote:
> The problem is this, both the python GUI and the ocaml tool need to know 
> how to parse/understand the configuration file format, and I'd like to 
> write the parser once (in ocaml, using ocamllex/yacc probably) and use it 
> twice (in the GUI and the base tool). My challenge now is to figure out how 
> to call the ocaml parser library from python.

How about not writing a parser at all?  In Python, use ConfigParser, and
in OCaml, use, erm, ConfigParser! :-)  (See
http://quux.org/devel/missinglib)  BTW, the ConfigParser in missinglib
will shortly have string interpolation in the same manner as Python has.

> I currently have two possibilities in mind. Surfing the web uncovered 
> Pycaml, which suggests integration both ways, however from the examples I 
> only understand how python can be called from ocaml (not the other way).

Hmm... what makes that a problem for you?  (What specifically are you
trying to do that requires you to call OCaml from Python?)

-- John

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  5:58 Max Powers
@ 2004-04-29  6:56 ` skaller
  2004-04-29 21:24 ` art yerkes
  1 sibling, 0 replies; 11+ messages in thread
From: skaller @ 2004-04-29  6:56 UTC (permalink / raw)
  To: Max Powers; +Cc: caml-list

On Thu, 2004-04-29 at 15:58, Max Powers wrote:

> So as I see it I've got the following options:
> 1) write the parser in ocaml. Wrap ocaml in C then wrap that using SWIG into 
> a python module.
> 2) write the parser in C. Use SWIG to generate Ocaml and python modules.
> 3) write the parser in python. Use Pycaml to call the python module from 
> Ocaml.

Ocaml is well suited to parsing and analysing
the parsed terms. If you head for (2) or (3) one needs
to ask why bother using Ocaml at all?

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
@ 2004-04-29  5:58 Max Powers
  2004-04-29  6:56 ` skaller
  2004-04-29 21:24 ` art yerkes
  0 siblings, 2 replies; 11+ messages in thread
From: Max Powers @ 2004-04-29  5:58 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

On Thu, 2004-04-29 at 15:33, skaller wrote:

>On Thu, 2004-04-29 at 15:07, Max Powers wrote:
> > >On Thu, 2004-04-29 at 13:49, skaller wrote:
>
> >  I.e. I can use SWIG to
> > generate an interface to a c library so I can use that from Ocaml, 
>rather
> > than generating an interface to expose Ocaml functions to a C (or other)
> > program.
>
>You can write a C wrapper for an Ocaml function in C,
>and then wrap THAT using SWIG so you can call it from Python.

Ahhh, right, I've got you now. Thanks for the clarification.

So as I see it I've got the following options:
1) write the parser in ocaml. Wrap ocaml in C then wrap that using SWIG into 
a python module.
2) write the parser in C. Use SWIG to generate Ocaml and python modules.
3) write the parser in python. Use Pycaml to call the python module from 
Ocaml.

The determining factor seems to be down to my preference for implementation 
language; I should be able to call functions and convert return types across 
each of these interfaces fairly easily. Is that a fair summary?

Ta,
-Max

_________________________________________________________________
SEEK: Now with over 50,000 dream jobs! Click here:  
http://ninemsn.seek.com.au?hotmail

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  3:09 Max Powers
  2004-04-29  3:49 ` skaller
@ 2004-04-29  5:45 ` Basile STARYNKEVITCH
  2004-04-29 14:16 ` John Goerzen
  2 siblings, 0 replies; 11+ messages in thread
From: Basile STARYNKEVITCH @ 2004-04-29  5:45 UTC (permalink / raw)
  To: Max Powers, caml-list

On Thu, Apr 29, 2004 at 12:39:24PM +0930, Max Powers wrote:
> This is a bit of a repeat of a question that I posted to comp.lang.python 
> (sorry to anyone who was there too!). I'm looking for some advice on 
> integrating a python GUI with an OCaml library. (Note: I'm fairly new to 
> both ocaml and python; more of a perl and c++ programmer!)

You might consider having the GUI in Python and the main OCaml program
be two different processes communicating thru pipes. You might even
consider using my GUIS program, which is a GUI GTK "server" listening
on an input pipe (which could be written by your Ocaml program)  for
Python commands and writing on an output pipe arbitrary textual stuff
(which have to be parsed by your Ocaml).

GUIS is available from http://starynkevitch.net/Basile/guisdoc.html 

(I intend to make a new release of GUIS in a few weeks - if you are
interested and/or want more features, it is the time to tell me).



-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  5:07 Max Powers
@ 2004-04-29  5:33 ` skaller
  0 siblings, 0 replies; 11+ messages in thread
From: skaller @ 2004-04-29  5:33 UTC (permalink / raw)
  To: Max Powers; +Cc: caml-list

On Thu, 2004-04-29 at 15:07, Max Powers wrote:
> >On Thu, 2004-04-29 at 13:49, skaller wrote:
> >
> >There is an Ocaml module in SWIG which may be useful to you.
> 
> Hmmm, forgive me if I'm totally off base with this, but I thought that SWIG 
> was used to interface a C library to other languages.

Yes.

>  I.e. I can use SWIG to 
> generate an interface to a c library so I can use that from Ocaml, rather 
> than generating an interface to expose Ocaml functions to a C (or other) 
> program. 

You can write a C wrapper for an Ocaml function in C,
and then wrap THAT using SWIG so you can call it from Python.

Writing C that wraps a simple function like

	parse_file: string -> ast

should be easy: string is the filename, and ast is 
a magical pointer to the parse tree. The wrapper would
make it a root of the Caml gc. 

You can probably do that now. Of course you won't
be able to use 'ast' to do anything, but at least
you can check you can invoke the parser on either
side of the interface without a core dump :D

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
@ 2004-04-29  5:07 Max Powers
  2004-04-29  5:33 ` skaller
  0 siblings, 1 reply; 11+ messages in thread
From: Max Powers @ 2004-04-29  5:07 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

>On Thu, 2004-04-29 at 13:49, skaller wrote:
>
>There is an Ocaml module in SWIG which may be useful to you.

Hmmm, forgive me if I'm totally off base with this, but I thought that SWIG 
was used to interface a C library to other languages. I.e. I can use SWIG to 
generate an interface to a c library so I can use that from Ocaml, rather 
than generating an interface to expose Ocaml functions to a C (or other) 
program. That reveals another option that I'd missed, I can write the parser 
in C (using the normal lex/yacc or even ANTLR!) and then provide both a 
python and Ocaml interface to that library.

>It sounds like you basically only need to call a single
>Ocaml parser function from Python to do the parsing which
>should be trivial.

Yeah, I think you're right (i.e. I think I can write the parser in Ocaml if 
required and it will be fairly simple). What I'm having trouble 
understanding is how to call the Ocaml function from python (i.e. how do I 
call any ocaml library function from python?).

>More difficult will be interpreting the parser output:
>that will be some Ocaml data structure like a parse tree
>you'll need to walk somehow from Python.
>
>On way to do that might be to get the Ocaml parse to
>build a parse tree made out of PyObjects.

Hmmm, very good point. Haven't thought about that yet... (I've got the 
feeling/hope that the output from the parser won't be too complex - should 
just be a few structs - after all, it's only a configuration file!).

Thanks for the help so far,
Max

_________________________________________________________________
SEEK: Now with over 50,000 dream jobs! Click here:  
http://ninemsn.seek.com.au?hotmail

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Calling Ocaml from Python
  2004-04-29  3:09 Max Powers
@ 2004-04-29  3:49 ` skaller
  2004-04-29  5:45 ` Basile STARYNKEVITCH
  2004-04-29 14:16 ` John Goerzen
  2 siblings, 0 replies; 11+ messages in thread
From: skaller @ 2004-04-29  3:49 UTC (permalink / raw)
  To: Max Powers; +Cc: caml-list

On Thu, 2004-04-29 at 13:09, Max Powers wrote:

> What I'm hoping is that someone on the list has tried this sort of thing 
> before and can give a little advice on the best way forwards (and hopefully 
> reduce the number of blind alleys I explore!).

There is an Ocaml module in SWIG which may be useful to you.
It sounds like you basically only need to call a single
Ocaml parser function from Python to do the parsing which
should be trivial.

More difficult will be interpreting the parser output:
that will be some Ocaml data structure like a parse tree
you'll need to walk somehow from Python.

On way to do that might be to get the Ocaml parse to
build a parse tree made out of PyObjects.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Caml-list] Calling Ocaml from Python
@ 2004-04-29  3:09 Max Powers
  2004-04-29  3:49 ` skaller
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Max Powers @ 2004-04-29  3:09 UTC (permalink / raw)
  To: caml-list

This is a bit of a repeat of a question that I posted to comp.lang.python 
(sorry to anyone who was there too!). I'm looking for some advice on 
integrating a python GUI with an OCaml library. (Note: I'm fairly new to 
both ocaml and python; more of a perl and c++ programmer!)

Basically the story is this, I'm building a GUI on the front of an existing 
OCaml tool. I'm writing the GUI in wxPython (there are a number of reasons 
why, I investigated various caml gui toolkits and unfortunately they didn't 
quite satisfy the requirements I had). Currently the GUI is envisaged as a 
glorified configuration file editor; it should help users to generate 
configuration files that are then handed to the ocaml tool to execute.

The problem is this, both the python GUI and the ocaml tool need to know how 
to parse/understand the configuration file format, and I'd like to write the 
parser once (in ocaml, using ocamllex/yacc probably) and use it twice (in 
the GUI and the base tool). My challenge now is to figure out how to call 
the ocaml parser library from python.

I currently have two possibilities in mind. Surfing the web uncovered 
Pycaml, which suggests integration both ways, however from the examples I 
only understand how python can be called from ocaml (not the other way).

The second possibility is to wrap the ocaml module in a c library that can 
then be imported into the python code.

What I'm hoping is that someone on the list has tried this sort of thing 
before and can give a little advice on the best way forwards (and hopefully 
reduce the number of blind alleys I explore!).

Thanks,
Max
(sorry for the length of the message and any abuse of the nomenclature!)

_________________________________________________________________
Personalise your phone with chart ringtones and polyphonics. Go to  
http://ringtones.com.au/ninemsn/control?page=/ninemsn/main.jsp

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-04-30  3:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-29  7:42 [Caml-list] Calling Ocaml from Python Max Powers
  -- strict thread matches above, loose matches on Subject: below --
2004-04-30  1:13 Max Powers
2004-04-29  5:58 Max Powers
2004-04-29  6:56 ` skaller
2004-04-29 21:24 ` art yerkes
2004-04-29  5:07 Max Powers
2004-04-29  5:33 ` skaller
2004-04-29  3:09 Max Powers
2004-04-29  3:49 ` skaller
2004-04-29  5:45 ` Basile STARYNKEVITCH
2004-04-29 14:16 ` John Goerzen

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).