This blog is about fxEngine, a statically typed formula engine for software that lets users write their own formulas. Typical examples include form builders, configurators and pricing tools. Since 2008, fxEngine has powered Calcapp, a platform for building calculator apps without code.
Static typing isn’t the norm for Excel-inspired formula engines. If your
formulas run interactively as part of a spreadsheet, perhaps getting an error
isn’t the end of the world (though those #VALUE! errors sure are hard to
decipher).
But if your formulas are running at 3 a.m. on a Sunday, crunching data, you want errors to be caught when the formulas are edited, not when they are run. fxEngine makes sure they are.
Origins
Back in 2003, I was an undergraduate studying computer science at Lund University in Sweden. My father, a doctor at a nearby hospital, needed an app for his department. It had to calculate the optimum nutritional content of the formula fed to preterm babies, based on the baby’s weight and the contents of the human milk.
To him, it was the culmination of many years of research. To me, it was a bunch of equations that meant little. Getting them into an app seemed easy enough, so I volunteered. Little did I know that calculators would come to define at least half of my career. I wound up calling the platform for creating apps Calcapp, perhaps owing to a lack of imagination.
The baby formula app was joined by a bigger brother, a drug calculator, and the complexity grew. In 2008, I finally dusted off what I had learned in a compiler course at university and integrated a lexer, parser and code generator into the system. While it wasn’t called fxEngine, that was the first version of it.
(Do you want to learn more about Calcapp’s history? This essay I wrote in 2018 has a lot more information.)
In 2013, Calcapp moved to the web, with a do-it-yourself app designer. My ambitions grew, and it became clear that the Calcapp I wanted needed to have an Excel-calibre formula engine. In 2016, I added support for hundreds of functions, and in 2017, properties like Visible and Recipients could be calculated by formulas.
The formula engine grew by leaps and bounds in 2021, with more than 100 new functions and support for arrays and ranges. I also wrote formula documentation over the course of three months, with thousands of formula examples. That documentation, with more words than Pride and Prejudice, is now the function reference of this site.
In 2023, support for imperative formulas, much-improved formula editing (with autocomplete and a function signature popup) and type inference were added.
fxEngine goes solo
Now, I’m taking the next logical step: decoupling the formula engine from Calcapp so that other products can use it too. It has been in production since 2008 and powers 50,000 apps.
Decoupling it is possible because of a habit of mine: I tend to keep polishing software long after it works. That has probably cost Calcapp’s customers a feature or two, as I’ve spent time refining the internals instead of working on new functionality.
But the habit has also led to some genuinely well-architected software, and Calcapp’s formula engine is one example. That isn’t great if you’re a customer wanting the labels for the fields in your app to be bold and purple (something Calcapp still doesn’t support). The upside is that you might one morning realize you can rip out the heart of your core product and offer it to other software developers for a fee, because it has been sturdily built and lends itself well to being ripped out.
I came to that realization almost five years ago, and registered fxengine.io.
Every year, I would renew the domain and feel a tinge of regret over still not
being in a position to get properly started. That “parked domain” default site
kept mocking me.
That changed a year ago, when I started working full-time on fxEngine.
Its primary components are fxEngine Compiler, which validates and compiles formulas, and fxEngine Runtime, which runs them. The compiler is written in Java, but runs on the web through TeaVM. The runtime is written in TypeScript, but runs on the JVM through GraalVM.
Other components will follow. fxEngine Editor is a formula editor for the web, based on CodeMirror, with code completion and function signatures being displayed as you type. fxEngine Validator checks Java object graphs against constraints, using code generated at build time rather than reflection. fxEngine API will compile, validate and calculate formulas over HTTP, from any language.
The plan is to make the compiler and runtime available under a license allowing for evaluation, personal use and experimentation (source-available, in other words), with a commercial license required for production use. The editor and the validator will be permissively licensed open source code, and the API a hosted service.
Eventually, we want to make all components of Calcapp available under the fxEngine brand. Calcapp will then be a demonstration of what can be accomplished with the fxEngine components.
fxEngine Shell, available today
None of the components listed above is available yet. There is one fxEngine product that is ready: fxEngine Shell.
It started life as the REPL example of fxEngine Compiler. I couldn’t help adding more features to it, and it became a standalone product, running happily in my terminal.
Put simply, fxEngine Shell allows you to name and evaluate formulas, which are type-checked before they are run. All types are inferred, not written out. It’s like a spreadsheet, without the grid.
The shell is reactive, meaning that all values are live:
> Rate = 25%
> Price = 400
> Tax = Price * Rate
> Rate = 50%
Tax is now 200.
Type errors are reported before formulas are run, here with messages written for spreadsheet users:
> /messages conversational
> TODAY() / 2
Expected a number but found a date or time instead
A spreadsheet would have returned a nonsensical number instead.
The shell can import and export CSV files and supports more than 400 functions,
including FILTER, SORTBY and
XLOOKUP. MAP and
REDUCE take lambdas written with an arrow, as in
MAP({ 1, 2, 3 }, V -> V * 2).
fxEngine Shell runs in your browser, with nothing to install. Give it
a try: the /tutorial command starts the interactive tutorials. Shell sessions
can be saved to a file and shared with others. A version for your terminal, and
the source code, will follow.
The shell itself will be permissively licensed, but it relies on the compiler and the runtime, which will be source-available. It’s free to use for any purpose if a human being is at the helm. Using it programmatically, through standard input and standard output, requires a license.
For me, it has replaced the Python REPL for quick calculations and LibreOffice for tracking the monthly household finances with my partner. So while the shell is a great demonstration of what fxEngine can do, it’s also useful in its own right.
About this blog
Over the past eleven years, I’ve written 278 blog posts for Calcapp’s blog. They are aimed at people who know how to work a spreadsheet but aren’t programmers, and focus on helping them get the most out of Calcapp.
This blog has a different audience: software engineers. Announcements, tutorials and company updates will appear in the Updates section, without a named author.
The Signed section will be different. I plan to write under my own name and liberally share my reflections on formulas, programming, business, LLMs and anything else that seems even tangentially related to fxEngine. I enjoy writing, and this way, I can give myself permission to do it during office hours. If it also happens to attract visitors to fxEngine, that will be a bonus.
Newsletter
We’re accepting sign-ups for our newsletter. You’ll get early access to the compiler and the runtime, and hear first when the other fxEngine components are released. We’ll also let you know when the shell can be downloaded for use in your own terminal.
If you’re building software whose users write formulas, I’d love to hear from you. My email address is just below.