From: Richard Jones <rich@annexia.org>
To: caml-list@inria.fr
Subject: [Caml-list] perl4caml (Call Perl code and functions from Objective Caml)
Date: Sat, 11 Oct 2003 19:36:43 +0100 [thread overview]
Message-ID: <20031011183643.GB17818@redhat.com> (raw)
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
next reply other threads:[~2003-10-11 18:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-11 18:36 Richard Jones [this message]
2003-10-11 20:36 ` Benjamin Geer
2003-10-12 12:12 ` Richard Jones
2003-10-12 17:37 ` Richard Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031011183643.GB17818@redhat.com \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).