<div dir="ltr"><div><div><div><div>Hi Chris,<br><br></div>Thanks:<br><br></div>1) You&#39;re right<br></div>2) Works perfectly<br></div>3) Will check with the FastR team<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 11, 2018 at 5:17 PM, Chris Seaton <span dir="ltr">&lt;<a href="mailto:chris.seaton@oracle.com" target="_blank">chris.seaton@oracle.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I guess your R.eval definition looks something like this?<div><br></div><div><div>  module R</div><div>    def self.eval(string)</div><div>      Polyglot.eval(&quot;R&quot;, string)</div><div>    end</div><div>  end</div><div><br></div><div>1) I don’t know anything about R personally, but running the standard version of R and experimenting, it looks like it does return the value.</div><div><br></div><div><div>  &gt; x = print(4)</div><div>  [1] 4</div><div>  &gt; x</div><div>  [1] 4</div></div><div><br></div><div>2) Does R have a way to ask values what type they are? If so you can call that from interop.</div><div><br></div><div>  module </div><div><div>    def self.typeof(object)</div><div>      eval(&quot;typeof&quot;).call(object)</div><div>    end</div></div><div>  end</div><div><br></div><div>  ...</div><div><br></div><div>  p R.typeof(val)</div><div><br></div><div>3) That’s something you could debate, but it looks like this is a specific design decision on the part of FastR, so it isn’t a mistake but you could open an issue with them if you think it’s wrong.</div><div><br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_oracle_fastr_blob_acc680f0d1168aa42d19174130f67c40ccc811b6_com.oracle.truffle.r.runtime_src_com_oracle_truffle_r_runtime_interop_R2Foreign.java-23L70-2DL73&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=snO7qWUwit0R73_5da034y4fMewRaZ3rQfRHIunK-eQ&s=-6T40Sol7J2t8OfJvERdyUL1J0T3Y4QRg-EXROt3vLk&e=" target="_blank">https://github.com/oracle/<wbr>fastr/blob/<wbr>acc680f0d1168aa42d19174130f67c<wbr>40ccc811b6/com.oracle.truffle.<wbr>r.runtime/src/com/oracle/<wbr>truffle/r/runtime/interop/<wbr>R2Foreign.java#L70-L73</a></div><div><br><blockquote type="cite"><div>On 11 May 2018, at 21:05, Oleg Šelajev &lt;<a href="mailto:oleg.selajev@oracle.com" target="_blank">oleg.selajev@oracle.com</a>&gt; wrote:</div><div><div class="h5"><br class="m_8204015079112257069Apple-interchange-newline"><div><div dir="auto"></div><div class="gmail_quote">---------- Forwarded message ----------<br>From: Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>&gt;<br>Date: 11 May 2018 22:11<br>Subject: [graalvm-users] Integration Ruby x R<br>To: <a href="mailto:graalvm-users@oss.oracle.com" target="_blank">graalvm-users@oss.oracle.com</a><br>Cc: <br><br type="attribution"><blockquote class="m_8204015079112257069quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hello Graalers...<br><br></div>I&#39;m trying to test and implement an integration between Ruby and R.  For that I have implemented this simple code where R.eval is a call to the R eval function.<br><br>    p R.eval(&quot;var = 4&quot;)<br>    p R.eval(&quot;print(var)&quot;)<br>    val = R.eval(&quot;var = 4&quot;)<br>    p val<br>    val = R.eval(&quot;var = c(1, 2, 3, 4)&quot;)<br>    p val<br>    p val[1]<br>    val = R.eval(&quot;list(1, 2, c(&#39;a&#39;, &#39;b&#39;, &#39;c&#39;))&quot;)<br>    p val<br>    p val[2][1]<br><br></div>I get the following results for this code:<br><br></div>4.0           # result of R.eval(&quot;var = 4&quot;)<br><div>[1] 4         # the print(var) in R<br></div><div>4.0           # result of R.eval(&quot;print(var)&quot;)<br></div><div>4.0           # p val<br></div><div>#&lt;Truffle::Interop::Foreign@<wbr>46994f26&gt;  # pointer to the c(1, 2, 3, 4) op<br></div><div>2.0           # p val[1]<br></div><div>#&lt;Truffle::Interop::Foreign@<wbr>2b8cf049&gt;  # pointer to the list<br>&quot;b&quot;           # p val[2][1]<br><br></div><div>My questions:<br><br></div><div>1) In R, if I&#39;m not mistaken print(var) has no return value.  Should we get 4.0 as return in this case?<br></div><div>2) The first pointer a foreign object points to a vector while the second pointer points to a list.  In this simple case, we know beforehand the type of the object, but in general this might not be true.  Is there any way to know the type of the object and to what messages it responds?  This seems critical to me to be able to really integrate both languages;<br></div><div>3) The result of R.eval(&quot;var = 4&quot;) in R is a vector, but we get back a float in Ruby.  For consistency, shouldn&#39;t this be a Ruby vector with 1 element? <br><br></div><div>Thanks<br></div><div><br><div><br clear="all"><div><div><br>-- <br><div>Rodrigo Botafogo<br><br></div>
</div></div></div></div></div>
</blockquote></div><br></div></div></div></blockquote></div><br></div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Rodrigo Botafogo<br>Integrando TI ao seu negócio<br>21-3010-4802/11-3010-1802</div>
</div>