<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=""> module R</div><div class=""> def self.eval(string)</div><div class=""> Polyglot.eval("R", string)</div><div class=""> end</div><div class=""> 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=""> > x = print(4)</div><div class=""> [1] 4</div><div class=""> > x</div><div class=""> [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=""> module </div><div class=""><div class=""> def self.typeof(object)</div><div class=""> eval("typeof").call(object)</div><div class=""> end</div></div><div class=""> end</div><div class=""><br class=""></div><div class=""> ...</div><div class=""><br class=""></div><div class=""> 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 <<a href="mailto:oleg.selajev@oracle.com" class="">oleg.selajev@oracle.com</a>> 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 <<a href="mailto:rodrigo.a.botafogo@gmail.com" class="">rodrigo.a.botafogo@gmail.com</a>><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. For that I have implemented this simple code where R.eval is a call to the R eval function.<br class=""><br class=""> p R.eval("var = 4")<br class=""> p R.eval("print(var)")<br class=""> val = R.eval("var = 4")<br class=""> p val<br class=""> val = R.eval("var = c(1, 2, 3, 4)")<br class=""> p val<br class=""> p val[1]<br class=""> val = R.eval("list(1, 2, c('a', 'b', 'c'))")<br class=""> p val<br class=""> p val[2][1]<br class=""><br class=""></div>I get the following results for this code:<br class=""><br class=""></div>4.0 # result of R.eval("var = 4")<br class=""><div class="">[1] 4 # the print(var) in R<br class=""></div><div class="">4.0 # result of R.eval("print(var)")<br class=""></div><div class="">4.0 # p val<br class=""></div><div class="">#<Truffle::Interop::Foreign@46994f26> # pointer to the c(1, 2, 3, 4) op<br class=""></div><div class="">2.0 # p val[1]<br class=""></div><div class="">#<Truffle::Interop::Foreign@2b8cf049> # pointer to the list<br class="">"b" # 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. 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. 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 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. 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>