Using .Call appears to force the promise:<br><br>msg=&quot;old&quot;<br>delayedAssign(&quot;x&quot;,msg)<br>msg=&quot;new&quot;<br>.Call(&#39;sexpType&#39;,x) # promise triggered here, returns 16<br>msg=&quot;even newer&quot; # will not change already fired promise<br>
.Call(&#39;sexpType&#39;,x) # returns 16<br>y = x<br>y # &quot;new&quot; (not &quot;even newer&quot;)<br><br>Here&#39;s sexpType:<br><br>RcppExport SEXP sexpType(SEXP x_) {<br>    return Rcpp::wrap(TYPEOF(x_));<br>}<br><br>
The type returned is 16 here (STRSXP). If numbers were<br>assigned to msg instead 14 would be returned (REALSXP).<br><br><div class="gmail_quote">On Fri, Dec 24, 2010 at 10:39 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 Fri, Dec 24, 2010 at 8:10 PM, Gabor Grothendieck<br>
&lt;<a href="mailto:ggrothendieck@gmail.com">ggrothendieck@gmail.com</a>&gt; wrote:<br>
&gt; How do I fix this so it works?  The code is intended to return TRUE or<br>
&gt; FALSE according to whether the variable with name nm in environment<br>
&gt; env is a promise or not.  In the example code below it returns FALSE<br>
&gt; but I would like it to return TRUE.  Is the promise being forced<br>
&gt; somewhere along the way?  Some other problem?<br>
&gt;<br>
&gt; library(Rcpp)<br>
&gt; f &lt;- cxxfunction(signature(env=&quot;environment&quot;, nm = &quot;character&quot;),<br>
&gt;        body=&#39; Environment e(env);<br>
&gt;           std::string s = as&lt;std::string&gt;(nm);<br>
&gt;           return wrap(TYPEOF (e[s]) == PROMSXP); &#39;,<br>
&gt;        plugin=&quot;Rcpp&quot;)<br>
&gt;<br>
&gt; # create promise<br>
&gt; delayedAssign(&quot;prom&quot;, 3)<br>
&gt;<br>
&gt; # want it to return TRUE but it returns FALSE<br>
&gt; f(.GlobalEnv, &quot;prom&quot;)<br>
<br>
</div>Or perhaps this is closer but it still does not work as intended:<br>
<br>
library(Rcpp)<br>
library(inline)<br>
f &lt;- cxxfunction(signature(s=&quot;SEXP&quot;),<br>
   body=&#39; return wrap(TYPEOF(s));&#39;,<br>
   plugin=&quot;Rcpp&quot;)<br>
<br>
f(f) # 3<br>
# note that promises are type 5 but we get:<br>
delayedAssign(&quot;prom&quot;, 3)<br>
f(prom) # 14<br>
<div><div></div><div class="h5"><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>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br>