From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B72FFBB84 for ; Thu, 3 Jul 2008 17:21:26 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhEBAHyLbEjRVcblemdsb2JhbACSBUMBAQsDBAYHEZlNhVI X-IronPort-AV: E=Sophos;i="4.27,742,1204498800"; d="scan'208";a="26991425" Received: from rv-out-0506.google.com ([209.85.198.229]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Jul 2008 17:21:26 +0200 Received: by rv-out-0506.google.com with SMTP id f6so920433rvb.3 for ; Thu, 03 Jul 2008 08:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=fwkge9grP15fxyaV1NLFZgefeoTZhukJtuPoc+UCMSM=; b=Tx0VSySoDCyBzoImcAvYVae5U1I+8an2SE6koN7+ghnpF31b/gk/dIkfAMnestTToF Qn1JG4vi5rqBm9TqlLpE2OrTd12jxlrjrVDbIZ95wfY4KObclWTl1K9VHPIeAnM67wTn QdquCftPe1AZ09iBQjFWwVbGJwsxbP48mRD5M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=gqerBPWKCnlqlk33LGY/B8F0caFN4coJe6Xud/xATGD+2PFqd4H9w8GCKBON7sxEK1 CBnalnqVrl2r375oQ2RYlURPJRBGGyU+rxo43QuzZ7Trkpz9Nrit6eKR1uyCEyXx7GLr CgAaI1WHQ+ndS5j2ObwhG+Ic3oxNZCjw9QgUA= Received: by 10.141.74.18 with SMTP id b18mr34018rvl.80.1215098484657; Thu, 03 Jul 2008 08:21:24 -0700 (PDT) Received: by 10.141.201.14 with HTTP; Thu, 3 Jul 2008 08:21:24 -0700 (PDT) Message-ID: <6999988a0807030821r1e11d042yd61b42dedd538620@mail.gmail.com> Date: Thu, 3 Jul 2008 11:21:24 -0400 From: "Peng Zhang" To: caml-list@yquem.inria.fr Subject: Re: call ocaml from R In-Reply-To: <6999988a0806241917p3d26a170s5ecfc8925e9d5e5d@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6999988a0806241917p3d26a170s5ecfc8925e9d5e5d@mail.gmail.com> X-Spam: no; 0.00; ocaml:01 ocaml:01 stub:01 mlvalues:01 alloc:01 val:01 peng:98 peng:98 wrote:01 compile:01 closure:01 closure:01 callback:02 callback:02 caml:02 Is it at all possible? Following the manual, I know I can call ocaml when C is the main program. I want to compile C file to Dynamic-link library, and call it from R. Can somebody help to answer it? Thanks, Peng On Tue, Jun 24, 2008 at 10:17 PM, Peng Zhang wrote: > Hi folks, > > I need some help from you. What I want to do is that my main program > is in R and I want to implement part of it with ocaml. > > The following is an example. > > /* mysin.R */ > dyn.load("mysin.so") > mysin <- function(x) > .C("mysin", as.double(x), r = double(1))$r > > /* mycode.ml */ > let sin_ml x = sin x > let _ = Callback.register "sin_ml" sin_ml > > I want to use sin defined in mycode.ml in mysin.R > > Then I write the following stub code > > /* mysin.c */ > #include > #include > #include > #include > #include > > void mysin(double * x, double * r){ > value * closure_f; > caml_startup(NULL); > closure_f = caml_named_value("sin_ml"); > *r = Double_val(caml_callback(*closure_f, caml_copy_double(*x))); > } > > It isn't working right now. What I am not sure about is what to put in > caml_startup. > > Can somebody help with me this? Thank you very much! > > Best, > Peng >