From t@r@@@z@kh@rko @end|ng |rom uzh@ch  Sun Mar  7 11:12:48 2021
From: t@r@@@z@kh@rko @end|ng |rom uzh@ch (Taras Zakharko)
Date: Sun, 7 Mar 2021 11:12:48 +0100
Subject: [Rd] An argument promise containing bytecode?
Message-ID: <7DD4C301-1849-4BAF-9C46-3256F09F79C9@uzh.ch>

Dear all, 

I was playing around with some C code that inspects argument promises and I noticed that forwarded arguments sometimes contain bytecode in the PRCODE component. E.g. if I have a nested call like this:

  f <- function(x) x
  g <- function(x) f(x)

 g(1+1)

and inspect the value of ?x? in g?s frame from within f?s frame (basically calling findVar(parent.frame(), x)), I would see a LANGSXP the first time g()  is invoked, but BCODESXP on every subsequent time.  Using PREXPR gets me the original LANGSXP in any case. 

Now, this is curious behavior and I had a quick glance into R source code related to closure evaluation and argument matching, but I could not see anything that would generate bytecode for promises. Could someone with in-depth knowledge of R?s machinery explain what is going on? 

Thanks, 

Taras


[Rd] An argument promise containing bytecode?
Taras Zakharko