Available on GitHub and hex.pm,
Matcha is a library for composing and using match specifications in Elixir. It’s intended to help you perform really fast, selective
:ets queries, and refine how you can study the function calls in your running programs.
A really powerful but difficult-to-use feature of the BEAM VM are match specifications. I’ve wrapped them with
Matcha to make them much more accessible to Elixir programmers, and am working hard to have great documentation on how to use them where they shine:
- Very efficiently getting specific data out of
- Very specifically tracing the runtime behaviour of your programs
Matcha works to solve: match specifications are already kind of a a chore to use from erlang code. This is compounded when trying to use them from Elixir, since they really just encode an informal erlang AST. Alchemists have to be familiar with erlang syntax and do a lot of mental context switching to tap into their benefits.
Additionally, the APIs and documentation around how to build and use them in
:ets and tracing is very dense. Some great guides exist out there, but I want to marry an easier-to-use-API with rich, first-class Elixir documentation and livebooks to make these topics more approachable.
I get into the why, how, and when of match specifications as they exist today in my ElixirConf 2022 talk. I also tease a library to help with them—and have been teasing it throughout its several years of intermittent development—and here we finally are.
Matcha employs Elixir’s macro system and compiler to convert familiar Elixir pattern matches into this oblique format, with rich compile-time validation, and exposes some nicer APIs for working with the resulting match specs.
In the holiday work lull, I’m able to find a little more time to pick up development again. My hope is to treat this thread as a bit of a devlog for now, and a changelog after a
v0.2.0 release with a more stable API. Hopefully I can entice some of you to check things out, and even help me improve it—especially the documentation.
Follow this thread, or the forum’s #matcha topic, to stay abreast of further developments!