From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA12826; Sat, 11 Oct 2003 20:36:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA24089 for ; Sat, 11 Oct 2003 20:36:45 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9BIai129904 for ; Sat, 11 Oct 2003 20:36:44 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 1A8Obb-00063w-00 for ; Sat, 11 Oct 2003 19:36:43 +0100 Date: Sat, 11 Oct 2003 19:36:43 +0100 To: caml-list@inria.fr Subject: [Caml-list] perl4caml (Call Perl code and functions from Objective Caml) Message-ID: <20031011183643.GB17818@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i From: Richard Jones X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pre-alpha:01 caml-:01 0.1.:01 cpan:01 cpan:01 mli:01 type-safe:01 adder:01 printf:01 -wt:99 scalar:01 printf:01 scalar:01 adder:01 freshmeat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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