Flexible Metaprogramming with Rhombus

chmaynard1 pts0 comments

Flexible metaprogramming with Rhombus [LWN.net]

LWN<br>.net<br>News from the source

Content Weekly Edition<br>Archives<br>Search<br>Kernel<br>Security<br>Events calendar<br>Unread comments

LWN FAQ<br>Write for us

User:<br>Password: |

Log in /<br>Subscribe /<br>Register

Flexible metaprogramming with Rhombus

[LWN subscriber-only content]

Welcome to LWN.net

The following subscription-only content has been made available to you<br>by an LWN subscriber. Thousands of subscribers depend on LWN for the<br>best news from the Linux and free software communities. If you enjoy this<br>article, please consider subscribing to LWN. Thank you<br>for visiting LWN.net!

By Daroc Alden<br>June 30, 2026

Lisp-like languages have historically led the world in metaprogramming and<br>flexibility. While many modern languages have adopted the idea of macros,<br>Lisp-like languages such as

Racket have continued pushing the envelope,<br>attempting to make macros as easy as possible to incorporate into everyday<br>programs. On the other hand, Lisp's minimal, parenthesis-based syntax can be hard<br>to adapt to — to the point that Lisp is sometimes said to stand<br>for "Lots of Irritating Silly Parentheses".

Rhombus is a new programming<br>language that aims to have the best of both worlds, marrying Racket's<br>metaprogramming capabilities to a simple Python-like syntax and reasonable<br>standard-library defaults.

The project

The language is part of the broader Racket project, which is "rooted in<br>academia". Of Rhombus's 43 contributors, the two most active are Matthew<br>Flatt and Wing Hei Chan, of the University of Utah and University of Hong Kong,<br>respectively. Rhombus is used as a teaching tool at both of their universities.<br>Despite that, the language aims to be more than just an academic<br>exercise. Development is supported by the<br>Racket Programming Language<br>Foundation, which seeks to make Racket and Rhombus suitable for real-world<br>professional use. Even though the language only

celebrated its 1.0 release on June 22, there is already

a set of tools for the Economancy card game partially written in it,<br>among other non-academic uses.

The core of Rhombus is available under either the MIT or Apache 2.0 license,<br>although it is built on top of the Racket runtime, which includes LGPL 3.0 code<br>in some dynamic libraries. That reuse of much of Racket's infrastructure means<br>that it already<br>has a large number of

usable libraries, and an optimizing compiler.<br>Rhombus programs can be interpreted, compiled to bytecode, or compiled to native<br>machine code.

One place that Rhombus differs from Racket, other than its syntax, is in its<br>choice of default data structures. Lisp-like languages often use singly linked<br>lists as a core data type, which comes with efficiency problems. Rhombus uses<br>lists backed by an immutable tree structure that makes many operations take<br>logarithmic time. Flat, mutable arrays, tree-based maps and sets, and hash-based<br>maps and sets are also available in the standard library.

The syntax

Rhombus's syntax is fairly similar to Python in that it is indentation-based,<br>and uses ":" to indicate the start of an indented block. One slight difference<br>is that Rhombus uses the "|" symbol to separate branches in if expressions<br>and similar contexts. The clearest way to explain is probably with an example<br>(an implementation of the factorial function):

fun factorial(n):<br>if n

Programmers with a more imperative bent might prefer the version below that uses a for<br>loop. Note the use of an inclusive range, 1..=n rather than the more common<br>exclusive range 1..n.

fun factorial(n):<br>def mutable p = 1<br>for (i in 1..=n):<br>p := p*i

By default, variables are immutable, so the

mutable binding operator is needed<br>to let the loop alter the value of p. The example can be made shorter,<br>however. Rhombus's for loops support a<br>feature that is uncommon outside of Lisp-like languages: an optional

"reducer"<br>that is used to combine the result of each loop into a final value for the loop<br>itself. The

math.product reducer multiplies all of the values returned<br>from the loop, allowing one to write:

fun factorial(n):<br>for math.product (i in 1..=n):

This ability means that Rhombus's equivalent of the list comprehensions found in<br>other languages is just a for loop that uses the

List reducer to<br>collect results into a list. For loops can also produce maps, sets, or even<br>boolean values using the

all or

any reducers. In a typical<br>programming language, one might expect this kind of built-in syntax to work for<br>the types provided by the standard library, but not for user-defined types.<br>Rhombus's macros, however, can be used to extend more or less any part of the<br>language, including creating new reducers. Most programs will probably not need<br>to do so, but it is nice to have the option when it would make the program<br>simpler.

Macros

Macros in Rhombus use single quotes to produce syntax objects that represent a<br>fragment of Rhombus code, with "$" used to indicate placeholders.<br>Unlike traditional Lisp-like languages that represent code with...

rhombus racket lisp languages syntax language

Related Articles