Lots of Function Transformations
The last couple of days I’ve been doing a lot of experimenting with a package for function rewriting: foolbox
. I am doing some function transformations in both pmatch
and tailr
and they look very much alike, so I figured I should collect the shared functionality in a separate package. After that, I found a work-around for the need for function rewriting in pmatch
, so it isn’t that necessary any longer, but playing around with foolbox
has been fun and taught me a lot of tricks for metaprogramming that I hadn’t thought about before.
I have written documentation on foolbox
’s homepage so I won’t repeat it here but refer you to
- Transforming functions with
foolbox
— general documentation of the package. - Partial evaluation with foolbox — implementation of partial evaluation using
foolbox
.
I am pretty sure that you can implement the function transformations with invariants and pre- and post-conditions similar to mikefc’s recent tweets:
Body modification in #rstats - merging the contents of 2 functions into a single function.https://t.co/XRAhiECmqq pic.twitter.com/61GmnT1eOQ
— mikefc (@coolbutuseless) March 17, 2018
Automatically creating runtime type checks for functions.
— mikefc (@coolbutuseless) March 18, 2018
An application of yesterday's method of merging 2 functions into a single body.https://t.co/HsaAwZ8pxl#rstats pic.twitter.com/amPnjJLUN2
Adding checks to an existing #rstats function - a slightly saner approach. https://t.co/dXEmdbX8Xo pic.twitter.com/Da7AnQF9hS
— mikefc (@coolbutuseless) March 20, 2018
A proposed method to check the change in a value *over* a block of #rstats code, e.g.
— mikefc (@coolbutuseless) March 22, 2018
assert_over(a == a + 1, {..code..}) https://t.co/CmX3AxYRrS pic.twitter.com/0ZJjkJ59Lr
#rstats testing: A function to check that an expression doesn't change during execution of a code block:
— mikefc (@coolbutuseless) March 22, 2018
assert_unchanged(statement, code)https://t.co/KBFunH03s4 pic.twitter.com/0euuw9ACJa
I also think that some static type checking should be possible (for a subset of functions, of course, R is way too dynamic a language to try to handle all cases).
I was thinking of making a release later this week or sometime next week and then return to working on pmatch
and tailr
. I might play around it a bit more first, though. In any case, I would love if anyone else would take it for a spin and help me debug it.