Gleam Syntax Postcard
A love letter to simplicity and smalltalk
Published on: Mon Apr 14 2025
Introduction
Smalltalk is a programming languages developed in the 1970s at Xerox PARC, a research and development company that pioneered many of modern computer concepts, such as graphical user interfaces and the computer mouse. One of its creators, Alan Kay, it attributed to have coined the term “object oriented programming (or OOP)”.
Unfortunately smalltalk has been largely forgotten and is not being taught at universities, as far as I know. But today I do not want to get into forgotten gems or the history and development of programming languages. I would like to talk about something else: syntax.
Syntax is at the core of every programming language, since there has to be a structured way to represent the concepts, that you are able to access in your program in a way, that a computer can process. Programming languages can also vary dramatically in complexity. C, one of the oldest and most used programming language, has a famously simple syntax. It only has 25 reserved keywords (depending on the standard, but roughly). For comparison, Java has 55 and C++ has 95!
Obviously the amount of keywords is not a perfect measure of general programming language complexity. But it does give an indication of the range of primitives, sugar syntax, etc. that it enables. And that is before we even talk about pre-processor pipelines, macros, etc, which can make a language very extensible, but thereby more complex.
And this is where smalltalk really takes the stage! All of its syntax, concepts and reserved keywords fit on a singular postcard. 8 lines of code and 255 characters.
This is the “relevant” syntax part, without the comment:
exampleWithNumber: x
|y|
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a "a" 1 1.0)
do: [:each | Transcript show: (each class name);
show: ' '].
^ x < y
No types, no async/await, not even explicit control flow. Just simple functions and blocks.
The Gleam Equivalent
As amazing as smalltalk is, it is not the star of today’s show. This is where Gleam joins us.
The slogan on its website is “Gleam is a friendly language for building type-safe systems that scale!”. In technical terms, it is a statically typed functional language, that compiles to Erlang and JavaScript and can run in both environments.
I could ramble for hours, how amazing, refreshing and productive I find Gleam to use, but let us get back to what all of this is about: the syntax.
Gleam deliberately leaves out a lot of more complex features, that you other wise find in programming langauges. It doesn’t have macros, sub-typing, type classes, unions, etc… So its type system is not nearly as complex or advanced as the likes of OCaml or Haskell. And that is not meant as an insult. Quite the contrary. It is simple enough for someone to pick it up without much hastle, but powerful enough to be able to build production systems.
And this is not to say, that Gleam does not have any nice features or syntax. Because it leaves out so much, it is really focused and gets the good stuff right: custom types, immutability, pattern matching, pipes (!), records and result & optional types. It is like an amazing concoction of the simplicity of C, the compiler feedback of Rust and the functional features of Elixir.
So in the spirit of simplicity and smalltalk, I tried to come up with a program that is syntactically correct and makes use of all of the concepts, that Gleam has to offer.
So, in all its glory, here it is:
(Made with ray.so)
Admittedly it is not as short and concise as the Smalltalk one. This version is still 48 lines of code. But that is ok, Gleam just is a bit more complex than Smalltalk.
Here is the Gleam code as a playground, if you would like to play around with it: Gleam Playground
And here is an overview of the concepts that are shown off (in no particular order):
- module imports
- functions & anonymous functions
- labelled arguments
- types (opaque, generics)
- let assignment
- working with records
- pattern matching
- guards
- pipes
- data types, tuples, lists
- bit arrays
- working with strings
- reserved keywords: panic, echo, assert, todo
usesugar syntax- comments
There are more concepts, that I was not able to squeeze in and one might consider a feature:
- JavaScript & Erlang FFI (https://tour.gleam.run/advanced-features/externals/)
- Function captures (https://tour.gleam.run/functions/function-captures/)
If you would like to take a deeper look at the Gleam syntax, check out the Tour!