<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Hi Stepan,</p>
<p style="margin:0px 0px 1.2em!important">I didn’t know about the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">[<-</code> function. Is this a standard R function or is this something that is provided by Graal?<br>I would love to have more detailed documentation that could help me do the Ruby x R interop. Anything you have is helpful.<br></p>
<p style="margin:0px 0px 1.2em!important">Ruby is very flexible and allow overriding operators like “[“. My intention is actually to write wraps to the whole R<br>language with Ruby allowing a Ruby programmer to work transparently in R. </p>
<p style="margin:0px 0px 1.2em!important">You can take a look at: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_rbotafogo_scicom_wiki_A-2D-28not-2Dso-29-2DShort-2DIntroduction-2Dto-2DSciCom&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=RBlRYePnq4KmOZDP2Oxeo7XfeGCfeYBwEZkdtOZCU14&s=GADKw3DrBgyEli6xS2LT_0-_cPNt0XoI_nvBUyrXssY&e=">https://github.com/rbotafogo/scicom/wiki/A-(not-so)-Short-Introduction-to-SciCom</a>,<br>for more information on what I intend to with fastR. This already works for Renjin.<br>Here for example is a code in Ruby (wrapping R in Renjin).</p>
<p style="margin:0px 0px 1.2em!important">This is a SciCom script to print the number of days for every month is 2005:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">require ‘scicom’
everyday = R.seq(from: R.as__Date('2005-1-1'), to: R.as__Date('2005-12-31'), by: 'day')<br>cmonth = everyday.format('%b')<br>cmonth<br> .factor(levels: cmonth.unique, ordered: TRUE)<br> .table<br> .pp
</code></pre><p style="margin:0px 0px 1.2em!important">Thanks</p>
<div title="MDH:PGRpdj5IaSBTdGVwYW4sPC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5JIGRpZG4ndCBrbm93IGFi
b3V0IHRoZSBgWyZsdDstYCBmdW5jdGlvbi4mbmJzcDsgSXMgdGhpcyBhIHN0YW5kYXJkIFIgZnVu
Y3Rpb24gb3IgaXMgdGhpcyBzb21ldGhpbmcgdGhhdCBpcyBwcm92aWRlZCBieSBHcmFhbD8gPGJy
PjwvZGl2PjxkaXY+SSB3b3VsZCBsb3ZlIHRvIGhhdmUgbW9yZSBkZXRhaWxlZCBkb2N1bWVudGF0
aW9uIHRoYXQgY291bGQgaGVscCBtZSBkbyB0aGUgUnVieSB4IFIgaW50ZXJvcC48YnI+PC9kaXY+
PGRpdj48YnI+PC9kaXY+PGRpdj5SdWJ5IGlzIHZlcnkgZmxleGlibGUgYW5kIGFsbG93IG92ZXJy
aWRpbmcgb3BlcmF0b3JzIGxpa2UgIlsiLiBNeSBpbnRlbnRpb24gaXMgYWN0dWFsbHkgdG8gd3Jp
dGUgd3JhcHMgdG8gdGhlIHdob2xlIFI8L2Rpdj48ZGl2Pmxhbmd1YWdlIHdpdGggUnVieSBhbGxv
d2luZyBhIFJ1YnkgcHJvZ3JhbW1lciB0byB3b3JrIHRyYW5zcGFyZW50bHkgaW4gUi4mbmJzcDsg
PGJyPjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+PGRpdj5Zb3UgY2FuIHRha2UgYSBsb29rIGF0
OiA8YSBocmVmPSJodHRwczovL2dpdGh1Yi5jb20vcmJvdGFmb2dvL3NjaWNvbS93aWtpL0EtKG5v
dC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dGUoJzIwMDUtMTIt
MzEnKSwgYnk6ICdkYXknKQogICAgICBjbW9udGggPSBldmVyeWRheS5mb3JtYXQoJyViJykKICAg
ICAgY21vbnRoCiAgICAgICAgLmZhY3RvcihsZXZlbHM6IGNtb250aC51bmlxdWUsIG9yZGVyZWQ6
IFRSVUUpCiAgICAgICAgLnRhYmxlCiAgICAgICAgLnBwCjwvY29kZT48L3ByZT5UaGFua3M8YnI+
PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj48YnI+PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jun 17, 2018 at 4:00 PM <<a href="mailto:graalvm-users-request@oss.oracle.com" target="_blank">graalvm-users-request@oss.oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send GraalVM-Users mailing list submissions to<br>
<a href="mailto:graalvm-users@oss.oracle.com" target="_blank">graalvm-users@oss.oracle.com</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:graalvm-users-request@oss.oracle.com" target="_blank">graalvm-users-request@oss.oracle.com</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:graalvm-users-owner@oss.oracle.com" target="_blank">graalvm-users-owner@oss.oracle.com</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of GraalVM-Users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: How to remove/opearte on an R vector through Interop? (Stepan)<br>
2. Re: Testing polyglot libs (Benoit Daloze)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sat, 16 Jun 2018 23:25:39 +0200<br>
From: Stepan <<a href="mailto:stepan.sindelar@oracle.com" target="_blank">stepan.sindelar@oracle.com</a>><br>
Subject: Re: [graalvm-users] How to remove/opearte on an R vector<br>
through Interop?<br>
To: <a href="mailto:graalvm-users@oss.oracle.com" target="_blank">graalvm-users@oss.oracle.com</a><br>
Message-ID: <<a href="mailto:97018432-d6e7-6d4b-b146-feb6b276b191@oracle.com" target="_blank">97018432-d6e7-6d4b-b146-feb6b276b191@oracle.com</a>><br>
Content-Type: text/plain; charset=utf-8; format=flowed<br>
<br>
Hi Rodrigo,<br>
<br>
I think the idea of Truffle interop is that once the object, in this <br>
case, R vector, goes into another language, the other language tries to <br>
treat it as if it were its "native" object. In this case, it means Ruby <br>
tries to apply the semantics of Ruby indexing to R vector. R vectors are <br>
immutable and cannot be modified, what looks like you're modifying data <br>
of a vector in R:<br>
<br>
myVector[42] <- newValue<br>
<br>
is in fact translated into (btw. you can execute this snippet as is too):<br>
<br>
myVector <- `[<-`(myVector, 42, newValue)<br>
<br>
There's a function called `[<-` that takes the vector as a first <br>
parameter and returns a new vector. The old vector stays unchanged (or <br>
at least any modifications must not be observable).<br>
<br>
What you can do is to retrieve the `[<-` function from R and use it:<br>
<br>
Ruby code:<br>
vec = Polyglot.eval("R", "c(1,2,3)")<br>
subsetAssign = Polyglot.eval("R", "`[<-`")<br>
vec = subsetAssign.call(vec, 1, 42)<br>
p vec[0]<br>
<br>
I don't know much of Ruby, but if Ruby allows overriding operators like <br>
"[" you can create a Ruby class that wraps R vector and delegates all <br>
the Ruby operations to appropriate R operations. This is what Rcpp <br>
package does with R and C++. Rcpp uses the ability to override various <br>
operators in C++ to provide R-like embedded DSL in C++ using the R to C <br>
interface (btw. supported by both GNU R and R in GraalVM). Building <br>
something like this in Ruby or any such flexible language would be an <br>
interesting project.<br>
<br>
We could, of course, support this approach natively in the Truffle <br>
interop, but that would mean doing the mapping of one semantics to <br>
another for all the language pairs, and interop aims to be generic. I <br>
think the current interop approach provides all the necessary primitives <br>
to implement such mapping in user code.<br>
<br>
Regards,<br>
Stepan<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Sun, 17 Jun 2018 20:31:41 +0200<br>
From: Benoit Daloze <<a href="mailto:eregontp@gmail.com" target="_blank">eregontp@gmail.com</a>><br>
Subject: Re: [graalvm-users] Testing polyglot libs<br>
To: Rodrigo Botafogo <<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>>,<br>
<a href="mailto:graalvm-users@oss.oracle.com" target="_blank">graalvm-users@oss.oracle.com</a><br>
Message-ID:<br>
<<a href="mailto:CANLTa0AgDCDkarivSRbZHHSbS0JoSSVhhfNiOb3fgxeCbrHQsA@mail.gmail.com" target="_blank">CANLTa0AgDCDkarivSRbZHHSbS0JoSSVhhfNiOb3fgxeCbrHQsA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Yes, it makes perfect sense.<br>
Actually we need that capability for mini_racer, where we want multiple<br>
JavaScript context from one Ruby context.<br>
<br>
Could you file an issue on <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=</a> with what<br>
you just explained to track progress on this more easily?<br>
<br>
On Fri, Jun 15, 2018 at 1:57 PM, Rodrigo Botafogo <<br>
<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>> wrote:<br>
<br>
> Benoit,<br>
><br>
> Actually, I think I have a pricise use case... let's say I'm building a<br>
> Web Application that at some point might need to develop a data model for<br>
> the user. In this case:<br>
><br>
> - I don't want my web application to be single threaded just because<br>
> eventually I'll need to interface with R to build a data model;<br>
> - Since building a data model is time usually consuming, then the best<br>
> would be do have a worker thread take care of this model while not<br>
> impacting user's interaction;<br>
> - Since different users might request different models, it would be<br>
> ideal if I could "instantiate" a new R for every users and run that on<br>
> there own threads.<br>
><br>
> Makes sense?<br>
><br>
><br>
> On Thu, Jun 14, 2018 at 4:54 PM Rodrigo Botafogo <<br>
> <a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>> wrote:<br>
><br>
>> Benoit,<br>
>><br>
>> At this point I don't really have a precise use case. If there is a flag<br>
>> to force multithread and the user calls R from two threads, I think<br>
>> crashing would be the safest thing for R to do!<br>
>><br>
>> It just seems a very strong restriction to prevent the code from running<br>
>> just because there is an integration. Letting it run with an override flag<br>
>> would allow the use cases to appear.<br>
>><br>
>> Thanks!<br>
>><br>
>> On Thu, Jun 14, 2018 at 4:00 PM Benoit Daloze <<a href="mailto:eregontp@gmail.com" target="_blank">eregontp@gmail.com</a>> wrote:<br>
>><br>
>>> Indeed, we'd like to allow such a scenario and we are trying to figure<br>
>>> out how to make this work and still be safe.<br>
>>><br>
>>> One interesting question is: what should happen if R is called from<br>
>>> another Ruby thread?<br>
>>><br>
>>> If you have a precise use-case in mind, could you post an issue on<br>
>>> <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_graal_issues&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=k7NRPYUa8hjmUxEjgM1rZa-K7Yt8fd_MlzBgZcYjifE&s=hJCnVwQXTVi6XYSKjhkjsNsQZRzY0vKyr3P7L26UrNs&e=</a> to track it more easily?<br>
>>><br>
>>> On Thu, Jun 14, 2018 at 7:44 PM, Rodrigo Botafogo <<br>
>>> <a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>> wrote:<br>
>>><br>
>>>> Thanks Benoit!<br>
>>>><br>
>>>> Now, is it really necessary to prevent multithreaded when interfacing<br>
>>>> Ruby and R? I understand that since R is not multithreaded, calling it<br>
>>>> from multiple threads will cause weird problems, but if the programmer is<br>
>>>> careful and say, only calls R from the same Ruby thread, everything should<br>
>>>> work fine, no? If this is the case, then could there be a flag to allow<br>
>>>> multithreaded applications even in the presence of R?<br>
>>>><br>
>>>> Thanks<br>
>>>><br>
>>>><br>
>>>> On Thu, Jun 14, 2018 at 2:38 PM Benoit Daloze <<a href="mailto:eregontp@gmail.com" target="_blank">eregontp@gmail.com</a>><br>
>>>> wrote:<br>
>>>><br>
>>>>> Note that one way to avoid MinitTest creating multiple threads is to<br>
>>>>> give it `N=0` like<br>
>>>>><br>
>>>>> $ N=0 ruby -Xsingle_threaded=true mytest.rb<br>
>>>>><br>
>>>>> I checked and this seems to work fine with GraalVM RC2 and minitest<br>
>>>>> 5.10.1 (bundled) and 5.11.3 (latest).<br>
>>>>><br>
>>>>> On Thu, Jun 14, 2018 at 5:25 PM, Rodrigo Botafogo <<br>
>>>>> <a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>>> Hello,<br>
>>>>>><br>
>>>>>> I'm trying to set up testing for my polyglot lib and I'm having a<br>
>>>>>> hard time. Sorry if I should post somewhere else...<br>
>>>>>><br>
>>>>>> So I tried to test with rspec, but rspec will run ruby somehow and<br>
>>>>>> does not pass to ruby the --polyglot --jvm flags. Polyglot complains that<br>
>>>>>> R is not a known language. I've googled around and could not find an easy<br>
>>>>>> way to make rspec pass flags to ruby.<br>
>>>>>><br>
>>>>>> Next I tried minitest, since in this case I call ruby directly with<br>
>>>>>> the required flags... but polyglot complains that R cannot execute in<br>
>>>>>> multithreaded, so I passed -Xsingle_threaded to ruby and minitest complains<br>
>>>>>> that it only runs in a multithreaded environment.<br>
>>>>>><br>
>>>>>> Any suggestions how to move forward?<br>
>>>>>><br>
>>>>>><br>
>>>>>> Thanks<br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>><br>
>>>>>> --<br>
>>>>>> Rodrigo Botafogo<br>
>>>>>><br>
>>>>>> _______________________________________________<br>
>>>>>> GraalVM-Users mailing list<br>
>>>>>> <a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>
>>>>>> <a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>
>>>>>><br>
>>>>><br>
>>>>><br>
>>>><br>
>>>> --<br>
>>>> Rodrigo Botafogo<br>
>>>> Integrando TI ao seu neg?cio<br>
>>>> 21-3010-4802/11-3010-1802<br>
>>>><br>
>>><br>
>>><br>
>><br>
>> --<br>
>> Rodrigo Botafogo<br>
>> Integrando TI ao seu neg?cio<br>
>> 21-3010-4802/11-3010-1802<br>
>><br>
><br>
><br>
> --<br>
> Rodrigo Botafogo<br>
> Integrando TI ao seu neg?cio<br>
> 21-3010-4802/11-3010-1802<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://oss.oracle.com/pipermail/graalvm-users/attachments/20180617/09c63ed8/attachment-0001.html" rel="noreferrer" target="_blank">http://oss.oracle.com/pipermail/graalvm-users/attachments/20180617/09c63ed8/attachment-0001.html</a> <br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
GraalVM-Users mailing list<br>
<a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>
<a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>
<br>
End of GraalVM-Users Digest, Vol 3, Issue 7<br>
*******************************************<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_-1684934944061292053gmail_signature" data-smartmail="gmail_signature">Rodrigo Botafogo<br>Integrando TI ao seu negócio<br>21-3010-4802/11-3010-1802</div>