christhekeele

christhekeele

Officially announcing Matcha!


Matcha

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.

Synopsis

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:

The Problem

The thing 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.

The Solution

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.

The Future

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!

Showing Posts 1 to 10

christhekeele

christhekeele OP

Fixed, thanks!

hst337

hst337

Great project!

hst337

hst337

By the way, is there any way to combine two specs together? Or put one spec into the other?

christhekeele

christhekeele OP

There’s a bit of discussion around that on GH: Support compile-time pattern / spec composition Ā· Issue #23 Ā· christhekeele/matcha Ā· GitHub, but it wanders off in other directions pretty quickly.

In short, I think it’s a good idea, and want to add it! The main thing I’m waiting on is understanding a few more people’s usecases before figuring out how it’d work. If you wanted to contribute to that issue’s discussion, it’d be very helpful!

kwando

kwando

I just played around with this library, love it so far :slight_smile: Not so intimidating to do efficient queries to ETS anymore :slight_smile:

christhekeele

christhekeele OP

I’ve just added a helper to latest to merge matchspecs. It comes with a few caveats, but should be useful for composing matches. It’ll be available next release!

hst337

hst337

I meant something like

merge(spec(do: [head | _] -> head), spec(do: {left, right} -> left + right))

To result in

spec(do: [{left, right} | _] -> left + right)
zachallaun

zachallaun

This seems pretty ambiguous, no? It’s not clear why the merge would know to replace the head binding specifically. What if there are two bindings?

It seems like, to get what you want, you’d need to be able to specify ā€œhigher orderā€ specs of some kind that explicitly declare the ā€œvarsā€ or whatever that you’re replacing.

var_spec([head], do: [head | _] -> head)

This seems somewhat complex. I wonder if there is a better approach that might allow ā€œnestingā€ but delegate composition to regular Elixir functions.

s1 = spec(do: {left, right} -> left + right})

spec bind: [head: s1] do
  [head | _] -> head
end

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API Ā· GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ausimian
Castle is a package I put together to assist with building Elixir releases capable of being live-upgraded via the ā€˜official’ release hand...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews