<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="">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://github.com/oracle/fastr/blob/acc680f0d1168aa42d19174130f67c40ccc811b6/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/interop/R2Foreign.java#L70-L73" class="">https://github.com/oracle/fastr/blob/acc680f0d1168aa42d19174130f67c40ccc811b6/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/interop/R2Foreign.java#L70-L73</a></div><div><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" class="">oleg.selajev@oracle.com</a>&gt; wrote:</div><br class="Apple-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" 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" class="">graalvm-users@oss.oracle.com</a><br class="">Cc: <br class=""><br type="attribution" class=""><blockquote class="quote" 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@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@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></blockquote></div><br class=""></div></body></html>