METABYTE
Back to articles

Recursion in STP: The Macro That Drives You Crazy but Works

How the STP macro processor manages to do recursion — and why it feels like gluing a broken vase with superglue.

12 mai 20262 min read
Recursion in STP: The Macro That Drives You Crazy but Works

Ever wondered if you can make macros recursive? If not, you've clearly never worked with STP. This macro processor, typically used for code generation or templating, suddenly turns out to be capable of actual recursion. And yes, it sounds like an oxymoron.

How It Works

STP (Standard Template Processor) isn't exactly a tool you'd associate with recursion. Usually macros just replace text, like a copywriter on a bad day. But STP lets you define macros that call themselves, creating loops. With one caveat: you need to be careful with exit conditions, otherwise your terminal will hang in an infinite loop, like Jira with 47 columns.

  • Example: a macro that calculates factorial. Yes, right in the macro. It looks like an incantation but works.
  • Limitations: STP isn't optimized for deep recursion. After 1000 iterations, it just crashes, like a developer after a night deploy.

Why Bother?

In real life, recursion in macros is like a Swiss Army knife: seems cool, but you use it once a year. However, for generating complex data structures or templates with repetitive elements, it's a lifesaver. For instance, you can create a macro that generates an HTML table with any nesting level. Or a Kubernetes config with tons of repetitive blocks.

Studio METABYTE's Comment

Recursion in macros is like finding a bug in production and realizing it was a feature. At METABYTE, we love such unexpected solutions, but we prefer code to be predictable. If you need something more complex than macros — we know how to do it without recursive puzzles.

NEXT STEP

Liked the approach?

We apply the same principles to client projects: AI, automation, products that don't die after launch.