* call ocaml from R
@ 2008-06-25 2:17 Peng Zhang
2008-07-03 15:21 ` Peng Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Peng Zhang @ 2008-06-25 2:17 UTC (permalink / raw)
To: caml-list
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 <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/callback.h>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: call ocaml from R
2008-06-25 2:17 call ocaml from R Peng Zhang
@ 2008-07-03 15:21 ` Peng Zhang
2008-07-03 17:29 ` [Caml-list] " Ashish Agarwal
0 siblings, 1 reply; 3+ messages in thread
From: Peng Zhang @ 2008-07-03 15:21 UTC (permalink / raw)
To: caml-list
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 <pczhang@gmail.com> 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 <caml/mlvalues.h>
> #include <caml/memory.h>
> #include <caml/alloc.h>
> #include <caml/custom.h>
> #include <caml/callback.h>
>
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Re: call ocaml from R
2008-07-03 15:21 ` Peng Zhang
@ 2008-07-03 17:29 ` Ashish Agarwal
0 siblings, 0 replies; 3+ messages in thread
From: Ashish Agarwal @ 2008-07-03 17:29 UTC (permalink / raw)
To: Peng Zhang; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]
There was some discussion about this on the main list, but there was no
clear answer.
http://groups.google.com/group/fa.caml/browse_thread/thread/46ad55d2102c1898/b92a26b04ce70c5d?lnk=gst&q=R#b92a26b04ce70c5d
On Thu, Jul 3, 2008 at 11:21 AM, Peng Zhang <pczhang@gmail.com> wrote:
> 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 <pczhang@gmail.com> 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 <caml/mlvalues.h>
> > #include <caml/memory.h>
> > #include <caml/alloc.h>
> > #include <caml/custom.h>
> > #include <caml/callback.h>
> >
> > 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
> >
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
[-- Attachment #2: Type: text/html, Size: 3196 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-03 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-25 2:17 call ocaml from R Peng Zhang
2008-07-03 15:21 ` Peng Zhang
2008-07-03 17:29 ` [Caml-list] " Ashish Agarwal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox