Hi all! I has been thinking in try a project which I don't know where to start, I'm checking if doing it and there is some reasons I would like to give it a try at work.
The idea is write rust code, be able to use r-a and everything, and then that code transform it to other language, for practical things I'll say/choose R for now, but would be nice keep in mind to do it with any language.
Why?
- Not all libs in R are or will be available in R
- Some times, due to company things, we need a final language like R
- Languages like R are not strong-typed, do this would really simplify and makes production code a lot nice!
- Be able to know what a variable is released, means we can find a way to when rust release a variable also remove it in this other language, reducing a lot the memory usage.
- There will be no issues with naming things, is usual in this langs just miss one word and you can't find the error unless there is a test
- Particularly R has a lot of weird behaviors! we can skip them
- Academic, be able to have some features like R, where ppl is more used to, and what to expect could do more easy introduce to Rust
- Clarity, just picking a example, all R functions makes copy of all elements all the time, is good to know this, would force us to write .clone() and know what we are doing
Well, this is some of the cases... going to the issue, any has any idea how to do this?
I tried checked on this, I would like to avoid this:
r_let!(let a = 10);
I thought in use attribute macros, this allow use to check all lines, and do the conversions for each instruction, the issue I found in this was that how to write the final result to a file, seems the attribute macros do not have a guarantee order or execution, still if with cargo clean
we can force it, still is fine, still no idea if this is the right thing.
I was thinking to implement something like a trait ToR
which would transform each expression to R, some parts must be done out (like in a macro), and this would help to organize the code better, because I would need to have the R libs, in this case how are the signatures of the types and functions, have modules with each lib and how they are transformed is nice.
There is also the alternative to write a app that reads rust code and transform to R, but this could also be complex, I would not even know how to call ToR
...
Ideas?
My ideal is be able to write something like (trivial example):
#[to_r, file = "foo.R"]
fn foo(a: f64, b: f64) -> r::sf::Point {
let a = a*2;
let b = b*a;
r::sf::Point::new_xy(a, b)
}
which could lead to
foo <- function(a, b) {
a <- a*2
b <- b*a
ret <- sf::st_point(c(a, b))
a <- NULL
b <- NULL
ret
}
Thx!