<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Here’s a more fun way to use typeof though:<div class=""><br class=""></div><div class=""><div class="">&nbsp; module R</div><div class="">&nbsp; &nbsp; def self.eval(string)</div><div class="">&nbsp; &nbsp; &nbsp; Polyglot.eval("R", string)</div><div class="">&nbsp; &nbsp; end</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; def self.method_missing(name, *args)</div><div class="">&nbsp; &nbsp; &nbsp; eval(name.to_s).call(*args)</div><div class="">&nbsp; &nbsp; end</div><div class="">&nbsp; end</div><div class=""><br class=""></div><div class="">var = R.eval("4")</div><div class="">val = R.c(1, 2, 3, 4)</div><div class="">p R.typeof(val)</div><div class="">p val</div><div class="">p val[1]</div><div class="">val = R.list(1, 2, R.c('a', 'b', 'c'))</div><div class="">p R.typeof(val)</div><div class="">p val</div><div class="">p val[2][1]</div><div class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 11 May 2018, at 21:26, Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" class="">rodrigo.a.botafogo@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Hi Chris,<br class=""><br class=""></div>Thanks:<br class=""><br class=""></div>1) You're right<br class=""></div>2) Works perfectly<br class=""></div>3) Will check with the FastR team<br class=""><br class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, May 11, 2018 at 5:17 PM, Chris Seaton <span dir="ltr" class="">&lt;<a href="mailto:chris.seaton@oracle.com" target="_blank" class="">chris.seaton@oracle.com</a>&gt;</span> wrote:<br class=""><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" class="">I guess your R.eval definition looks something like this?<div class=""><br class=""></div><div class=""><div class="">&nbsp; module R</div><div class="">&nbsp; &nbsp; def self.eval(string)</div><div class="">&nbsp; &nbsp; &nbsp; Polyglot.eval("R", string)</div><div class="">&nbsp; &nbsp; end</div><div class="">&nbsp; end</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><div class="">&nbsp; &gt; x = print(4)</div><div class="">&nbsp; [1] 4</div><div class="">&nbsp; &gt; x</div><div class="">&nbsp; [1] 4</div></div><div class=""><br class=""></div><div class="">2) Does R have a way to ask values what type they are? If so you can call that from interop.</div><div class=""><br class=""></div><div class="">&nbsp; module&nbsp;</div><div class=""><div class="">&nbsp; &nbsp; def self.typeof(object)</div><div class="">&nbsp; &nbsp; &nbsp; eval("typeof").call(object)</div><div class="">&nbsp; &nbsp; end</div></div><div class="">&nbsp; end</div><div class=""><br class=""></div><div class="">&nbsp; ...</div><div class=""><br class=""></div><div class="">&nbsp; p R.typeof(val)</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><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&amp;d=DwMFaQ&amp;c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&amp;r=GeKqXC_6SKmJdrXPk9-xeQQoxGJV5kRmq9tMEP11foo&amp;m=uTNrIujt6kNfAXmIXeWj0kHDX14Wnh7esjI_DxcCAvA&amp;s=Y3R_JsdqrFOQBLD1zlOzeAtOX8qLsDVHAAY-V5CYliA&amp;e=" target="_blank" class="">https://github.com/oracle/<wbr class="">fastr/blob/<wbr class="">acc680f0d1168aa42d19174130f67c<wbr class="">40ccc811b6/com.oracle.truffle.<wbr class="">r.runtime/src/com/oracle/<wbr class="">truffle/r/runtime/interop/<wbr class="">R2Foreign.java#L70-L73</a></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 11 May 2018, at 21:05, Oleg Šelajev &lt;<a href="mailto:oleg.selajev@oracle.com" target="_blank" class="">oleg.selajev@oracle.com</a>&gt; wrote:</div><div class=""><div class="h5"><br class="m_8204015079112257069Apple-interchange-newline"><div class=""><div dir="auto" class=""></div><div class="gmail_quote">---------- Forwarded message ----------<br class="">From: Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank" class="">rodrigo.a.botafogo@gmail.com</a>&gt;<br class="">Date: 11 May 2018 22:11<br class="">Subject: [graalvm-users] Integration Ruby x R<br class="">To: <a href="mailto:graalvm-users@oss.oracle.com" target="_blank" class="">graalvm-users@oss.oracle.com</a><br class="">Cc: <br class=""><br type="attribution" class=""><blockquote class="m_8204015079112257069quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class="">Hello Graalers...<br class=""><br class=""></div>I'm trying to test and implement an integration between Ruby and R.&nbsp; For that I have implemented this simple code where R.eval is a call to the R eval function.<br class=""><br class="">&nbsp;&nbsp;&nbsp; p R.eval("var = 4")<br class="">&nbsp;&nbsp;&nbsp; p R.eval("print(var)")<br class="">&nbsp;&nbsp;&nbsp; val = R.eval("var = 4")<br class="">&nbsp;&nbsp;&nbsp; p val<br class="">&nbsp;&nbsp;&nbsp; val = R.eval("var = c(1, 2, 3, 4)")<br class="">&nbsp;&nbsp;&nbsp; p val<br class="">&nbsp;&nbsp;&nbsp; p val[1]<br class="">&nbsp;&nbsp;&nbsp; val = R.eval("list(1, 2, c('a', 'b', 'c'))")<br class="">&nbsp;&nbsp;&nbsp; p val<br class="">&nbsp;&nbsp;&nbsp; p val[2][1]<br class=""><br class=""></div>I get the following results for this code:<br class=""><br class=""></div>4.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # result of R.eval("var = 4")<br class=""><div class="">[1] 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # the print(var) in R<br class=""></div><div class="">4.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # result of R.eval("print(var)")<br class=""></div><div class="">4.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # p val<br class=""></div><div class="">#&lt;Truffle::Interop::Foreign@<wbr class="">46994f26&gt;&nbsp; # pointer to the c(1, 2, 3, 4) op<br class=""></div><div class="">2.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # p val[1]<br class=""></div><div class="">#&lt;Truffle::Interop::Foreign@<wbr class="">2b8cf049&gt;&nbsp; # pointer to the list<br class="">"b"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # p val[2][1]<br class=""><br class=""></div><div class="">My questions:<br class=""><br class=""></div><div class="">1) In R, if I'm not mistaken print(var) has no return value.&nbsp; Should we get 4.0 as return in this case?<br class=""></div><div class="">2) The first pointer a foreign object points to a vector while the second pointer points to a list.&nbsp; In this simple case, we know beforehand the type of the object, but in general this might not be true.&nbsp; Is there any way to know the type of the object and to what messages it responds?&nbsp; This seems critical to me to be able to really integrate both languages;<br class=""></div><div class="">3) The result of R.eval("var = 4") in R is a vector, but we get back a float in Ruby.&nbsp; For consistency, shouldn't this be a Ruby vector with 1 element? <br class=""><br class=""></div><div class="">Thanks<br class=""></div><div class=""><br class=""><div class=""><br clear="all" class=""><div class=""><div class=""><br class="">-- <br class=""><div class="">Rodrigo Botafogo<br class=""><br class=""></div>
</div></div></div></div></div>
</blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""><br clear="all" class=""><br class="">-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature">Rodrigo Botafogo<br class="">Integrando TI ao seu negócio<br class="">21-3010-4802/11-3010-1802</div>
</div>
</div></blockquote></div><br class=""></div></body></html>