<br><br><div class="gmail_quote">On Sat, Dec 25, 2010 at 4:08 PM, Gabor Grothendieck <span dir="ltr">&lt;<a href="mailto:ggrothendieck@gmail.com">ggrothendieck@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Sat, Dec 25, 2010 at 3:58 PM, Dominick Samperi &lt;<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>&gt; wrote:<br>
&gt; Using .Call appears to force the promise:<br>
&gt;<br>
&gt; msg=&quot;old&quot;<br>
&gt; delayedAssign(&quot;x&quot;,msg)<br>
&gt; msg=&quot;new&quot;<br>
&gt; .Call(&#39;sexpType&#39;,x) # promise triggered here, returns 16<br>
&gt; msg=&quot;even newer&quot; # will not change already fired promise<br>
&gt; .Call(&#39;sexpType&#39;,x) # returns 16<br>
&gt; y = x<br>
&gt; y # &quot;new&quot; (not &quot;even newer&quot;)<br>
&gt;<br>
&gt; Here&#39;s sexpType:<br>
&gt;<br>
&gt; RcppExport SEXP sexpType(SEXP x_) {<br>
&gt;     return Rcpp::wrap(TYPEOF(x_));<br>
&gt; }<br>
&gt;<br>
&gt; The type returned is 16 here (STRSXP). If numbers were<br>
&gt; assigned to msg instead 14 would be returned (REALSXP).<br>
&gt;<br>
<br>
</div>Note that the first attempt I posted tried to get around that by<br>
passing the environment and the name of the variable in the<br>
environment so that the object would not itself be passed yet it did<br>
not work either.  Here is a slight variation:<br></blockquote><div><br>Yes, I tired your variant (just passing the environment) but it<br>still doesn&#39;t work. Here is the explanation: Rcpp currently<br>implements e[] (i.e., operator [] for Environment) via get(),<br>
and when the variable is a promise it evaluates, effectively<br>forcing the promise. There is a Rcpp::Promise class, but it is<br>probably work in progress because it is not exposed.<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
&gt; library(Rcpp)<br>
&gt; library(inline)<br>
<div class="im">&gt; f &lt;- cxxfunction(signature(env=&quot;environment&quot;, nm = &quot;character&quot;),<br>
+        body=&#39; Environment e(env);<br>
+           std::string s = as&lt;std::string&gt;(nm);<br>
</div>+           return wrap(TYPEOF (e[s])); &#39;,<br>
+        plugin=&quot;Rcpp&quot;)<br>
<div class="im">&gt;<br>
&gt; # create promise<br>
&gt; delayedAssign(&quot;prom&quot;, 3)<br>
&gt;<br>
</div>&gt; # want it to return 5 but it returns 14<br>
&gt; f(.GlobalEnv, &quot;prom&quot;)<br>
[1] 14<br>
<div><div></div><div class="h5"><br>
<br>
<br>
--<br>
Statistics &amp; Software Consulting<br>
GKX Group, GKX Associates Inc.<br>
tel: 1-877-GKX-GROUP<br>
email: ggrothendieck at <a href="http://gmail.com" target="_blank">gmail.com</a><br>
</div></div></blockquote></div><br>