Welcome to LWN.net The following subscription-only content has been made available to you by an LWN subscriber. Thousands of subscribers depend on LWN for the best news from the Linux and free software communities. If you enjoy this article, please consider subscribing to LWN. Thank you for visiting LWN.net!
Lisp-like languages have historically led the world in metaprogramming and flexibility. While many modern languages have adopted the idea of macros, Lisp-like languages such as Racket have continued pushing the envelope, attempting to make macros as easy as possible to incorporate into everyday programs. On the other hand, Lisp's minimal, parenthesis-based syntax can be hard to adapt to — to the point that Lisp is sometimes said to stand for "Lots of Irritating Silly Parentheses". Rhombus is a new programming language that aims to have the best of both worlds, marrying Racket's metaprogramming capabilities to a simple Python-like syntax and reasonable standard-library defaults.
The project
The language is part of the broader Racket project, which is " rooted in academia ". Of Rhombus's 43 contributors, the two most active are Matthew Flatt and Wing Hei Chan, of the University of Utah and the Chinese University of Hong Kong, respectively. Rhombus is used as a teaching tool at both of their universities the University of Utah; Chan contributes to Rhombus independently, and doesn't actually work in the Chinese University of Hong Kong's computer-science department. Despite that, the language aims to be more than just an academic exercise. Development is supported by the Racket Programming Language Foundation, which seeks to make Racket and Rhombus suitable for real-world 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, among other non-academic uses.
The core of Rhombus is available under either the MIT or Apache 2.0 license, although it is built on top of the Racket runtime, which includes LGPL 3.0 code in some dynamic libraries. That reuse of much of Racket's infrastructure means that it already has a large number of usable libraries, and an optimizing compiler. Rhombus programs can be interpreted, compiled to bytecode, or compiled to native machine code.
One place that Rhombus differs from Racket, other than its syntax, is in its choice of default data structures. Lisp-like languages often use singly linked lists as a core data type, which comes with efficiency problems. Rhombus uses lists backed by an immutable tree structure that makes many operations take logarithmic time. Flat, mutable arrays, tree-based maps and sets, and hash-based 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, and uses ":" to indicate the start of an indented block. One slight difference is that Rhombus uses the "|" symbol to separate branches in if expressions and similar contexts. The clearest way to explain is probably with an example (an implementation of the factorial function):
fun factorial(n): if n <= 1 | 1 | n * factorial(n - 1)
Programmers with a more imperative bent might prefer the version below that uses a for loop. Note the use of an inclusive range, 1..=n rather than the more common exclusive range 1..n .
... continue reading