<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/0ca9dd67085538189eddebc7ca2fd3ad"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-11T18:36:47"
  subject="[Caml-list] perl4caml (Call Perl code and functions from Objective Caml)"
  prev="2003/10/a3eaae7edc5a48d4439ca503fc8f316c"
  next="2003/10/d29b2f8046cd0aec7b4513f6488a91cb"
  next-in-thread="2003/10/1d4b1b44e3e187ccedd5bf3f902aee30"
  prev-thread="2003/10/c346cedb5666799fc0064496fa9553ba"
  next-thread="2003/10/d29b2f8046cd0aec7b4513f6488a91cb"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] perl4caml (Call Perl code and functions from Objective Caml)">
<msg 
  url="2003/10/0ca9dd67085538189eddebc7ca2fd3ad"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-11T18:36:47"
  subject="[Caml-list] perl4caml (Call Perl code and functions from Objective Caml)">
<msg 
  url="2003/10/1d4b1b44e3e187ccedd5bf3f902aee30"
  from="Benjamin Geer &lt;ben@s...&gt;"
  author="Benjamin Geer"
  date="2003-10-11T20:36:48"
  subject="Re: [Caml-list] perl4caml (Call Perl code and functions from Objective Caml)">
</msg>
<msg 
  url="2003/10/88a79674700624c6fd449f29bb61bc8c"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-12T12:12:45"
  subject="Re: [Caml-list] perl4caml (Call Perl code and functions from Objective Caml)">
<msg 
  url="2003/10/04a1b9643e8d392be1dfda4388458737"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-10-12T17:37:17"
  subject="Re: [Caml-list] perl4caml (Call Perl code and functions from Objective Caml)">
</msg>
</msg>
</msg>
</thread>

<contents>
Perhaps controversially I've written a prototype, pre-alpha interface
for calling Perl code from OCaml. You can download it here:

http://www.annexia.org/tmp/perl4caml-0.1.tar.gz

The long term aim here is to be able to utilise the huge resource that
is CPAN (http://www.cpan.org/) from within OCaml. It wouldn't be
completely automatic because of course you would still need to write
interface specifications (similar in concept to .mli files) to make
things type-safe.

A wrapped Perl library would never be as fast or efficient as a native
OCaml implementation, but at least the option would be there.

Rich.

Here is an example:

----- test.pl

sub return1
  {
    print "this is the 'return1' function!\n";
    1;
  }

sub adder
  {
    $_[0] + $_[1]
  }

----- test.ml

open Printf

let () =
  (* Arguments passed to the Perl "command line". Loads [test.pl] *)
  let args = [| ""; "-wT"; "test.pl" |] in

  (* Create the Perl interpreter. *)
  let pl = Perl.create ~args () in

  (* Call some subroutines in [test.pl]. *)
  let sv = Perl.call_scalar "return1" [] in
  printf "return1 = %d\n" (Perl.int_of_sv sv);

(*
  let sv = Perl.call_scalar "adder" [`Int 3; `Int 4] in
  printf "adder (3, 4) = %d\n" (Perl.int_of_sv sv);
*)

(*
  (* Evaluate a simple expression. *)
  Perl.eval "$a = 3";
  printf "$a contains %d\n" (Perl.int_of_sv (Perl.get_sv "a"));
*)

  (* Destroy the interpreter. *)
  Perl.destroy pl

-----

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/

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

</contents>

</message>

