For some reason, I would like to play with R-calls (at least in syntax) in a more Lisp / Scheme-like style (we all know that R was strongly inspired by Scheme ).
So I installed the following function:
. <- function(f, ...) eval(match.call()[-1], envir=parent.frame())
Which allows me to express, for example. following R code:
x <- sort(sample(1:10, 5, replace=TRUE)) for (i in x) { print(1:i) }
in the following semantically equivalent form:
.(`<-`, x, .(sort, .(sample, .(`:`, 1, 5), 5, replace=TRUE))) .(`for`, i, x, .(`{`, .(print, .(`:`, 1, i))))
I am quite pleased with the current definition . (as it was done for pleasure). But he is certainly far from perfect. In particular, its performance is, of course, poor:
microbenchmark::microbenchmark(1:10, .(`:`, 1, 10)) ## Unit: nanoseconds ## expr min lq median uq max neval ## 1:10 189 212.0 271.5 349 943 100 ## .(`:`, 1, 10) 8809 10134.5 10763.0 11467 44066 100
So, would you be interested to come up with some ideas regarding the definition . that could solve the above problem. C / C ++ code is welcome.