<br><br><div class="gmail_quote">On Sat, Dec 25, 2010 at 4:08 PM, Gabor Grothendieck <span dir="ltr"><<a href="mailto:ggrothendieck@gmail.com">ggrothendieck@gmail.com</a>></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 <<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>> wrote:<br>
> Using .Call appears to force the promise:<br>
><br>
> msg="old"<br>
> delayedAssign("x",msg)<br>
> msg="new"<br>
> .Call('sexpType',x) # promise triggered here, returns 16<br>
> msg="even newer" # will not change already fired promise<br>
> .Call('sexpType',x) # returns 16<br>
> y = x<br>
> y # "new" (not "even newer")<br>
><br>
> Here'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>
<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'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>
> library(Rcpp)<br>
> library(inline)<br>
<div class="im">> f <- cxxfunction(signature(env="environment", nm = "character"),<br>
+ body=' Environment e(env);<br>
+ std::string s = as<std::string>(nm);<br>
</div>+ return wrap(TYPEOF (e[s])); ',<br>
+ plugin="Rcpp")<br>
<div class="im">><br>
> # create promise<br>
> delayedAssign("prom", 3)<br>
><br>
</div>> # want it to return 5 but it returns 14<br>
> f(.GlobalEnv, "prom")<br>
[1] 14<br>
<div><div></div><div class="h5"><br>
<br>
<br>
--<br>
Statistics & 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>