r v0.4.0
"Wonder Where We Land"
This release brings a multitude of fresh language features, supercharging internal vector management and bringing R's metaprogramming facilities to life. Read on to dig into each new feature below. Though this project still bears the name "R", it is slowly aquiring a life of its own.
Powerful Internals
by @sebffischer
In 2018, R introduced a concept called
altreps - alternative
representations for vectors to avoid costly computation until it was
absolutely necessary. R has a few of these tricks up its sleeve, primarily
designed to improve calculations on ranges without the need to fill out a
full vector; or to speed up a few calculations based on some characteristics
of the vectors themselves like whether they include missing
(NA
) values.
This release adopts this feature, but with the benefit of hindsight, allows us to embed this idea more foundationally in the language. Currently only a single altrep is implemented -- a subset of a vector. This single representation comes in to play frequently and lets us avoid constant data copies!
Let's imagine we have a block of structured data. In this example it's buried in a list:
In R, modifying this interior data comes at a steep cost since each view is copied for modification and then a new copy of the original data is created prior to insertion of newly modified contents.
With a subset representation, we can delay modification until we know exactly which elements will be updated, and modify them in-place. If in-place modification doesn't sound like R to you, you're right, and that takes us to our next huge feature!
Mutable Views
by @sebffischerThis is an odd feature to showcase. If it's working as intended, you'll never know that it's even there. Don't let that detract from its significance, though. There are a few new tricks that are easy to miss.
When assigning from one R object to another, both objects will point to the same underlying data. This goes for the R objects themselves, as well as references to those objects in our subset representation. They'll remain identical until one of them is modified, at which point they both get unique identities. By waiting until absolutely necessary, we save on the initial copy when creating an object, but we also leverage this to avoid intermediate copies when assigning to subsets.
Language Localizations
with the help of @sebffischer, @LornebradiaProgramming is for everyone, and that means making concepts more intuitive and expressive. Whether a beginner or an expert, having the ability to code in one's native tongue makes programming a more welcoming experience.
This is one step along that path. If this work proves valuable, future work could include automatic translation of localized code and facilities for localizing function names.
Metaprogramming Updates
R, and Lisp before it, are renowned for their metaprogramming. In fact, R gives an unparalleled capacity for evaluation in environments, regardless of where they live in the call stack. This unique feature is what makes R a wildly expressive language for building domain-specific languages.
This update brings many metaprogramming primitives. The ability to
quote()
and eval()
code - the building blocks
of R's expressiveness.
Rapid-fire Updates
And a handful of quality-of-life changes that deserve special recognition
- Numerics now permit underscore separators for readability (
1_000_000
) by @sebffischer - Environment symbol look-up will be faster due to a faster hashing function by @sebffischer
- The
..rest
syntax has been generalized to cover ellipses, closing the gap for stabilization - Developers will appreciate that printing environment debug output will no longer infinitely recurse @sebffischer
- The "not" operator (
!
) finally got an implementation after being initially overlooked - The live browser repl now does syntax highlighting and input validation, and will print output as it is emitted to the console during long-running code.
- Experiments are now toggleable by command line flags (using
--experiments=
), avoiding the need for recompilation to test experimental features.
Thanks to all Contributors!
With an especially big thank you going out to @sebffischer who dove deep into the internals in order to improve some central behaviors of the language.
If you're interested in getting involved, there are plenty of discussions on language features, and some good first issues!