Est. 2005 Advanced

Glass

An esoteric language from 2005 that welds Forth-style postfix stack juggling to Smalltalk-style object orientation, pushing even addition and subtraction out of the syntax and into methods on built-in classes.

Created by Gregor Richards

Paradigm Stack-based and object-oriented: a single global operand stack in postfix notation, combined with classes, instances, constructors and four scopes of variable
Typing Dynamic and implicit. Stack cells hold numbers, strings, variable names, class references, object references or bound functions; there are no declarations and no type annotations
First Appeared 2005
Latest Version Reference interpreter 0.12, a C++ program released under the GPL. The file timestamps inside the archived tarball are dated 25 October 2005; no later reference release is known

Glass is an esoteric programming language created by Gregor Richards in 2005. Its premise is a collision: take the postfix, single-stack execution model of Forth, and take the everything-is-an-object discipline of Smalltalk, and refuse to compromise either one. The result is a language where you cannot add two numbers without first instantiating a class, retrieving a method from it, and calling that method with both operands sitting on a global stack. The specification’s own summary of the idea is unimprovable: “No other language that the author knows of is implemented like this, because it would be idiotic.”

That sentence is the joke, but the language underneath it is not a joke in the way that, say, a randomly-generated syntax is. Glass is coherently specified, Turing complete, and has been used to write a brainfuck interpreter and a quine. It belongs to the useful branch of esoterica - languages built to make a real design idea uncomfortable enough that you have to look at it.

History and Origins

Glass appeared in 2005 from Gregor Richards, who was by then a prolific contributor to the esoteric-language community. His other work includes the languages 2L, FukYorBrane and ORK, the EgoBF suite of brainfuck interpreters and compilers, the EgoBot IRC bot, and tooling for BF Joust - the brainfuck-program duelling game that occupied the esolangs IRC channel for years.

That context explains a lot about Glass. The reference interpreter ships with a shell script and a -DIRC build flag that turn it into an IRC bot, so that Glass programs could be typed into a channel and evaluated in front of an audience. The language was designed to be shown off in a chat window, which is part of why its syntax is so aggressively compressed: parentheses around identifiers are optional for single characters, and idiomatic Glass therefore uses single-letter names almost everywhere.

The distributed record is thin but consistent. Two source snapshots survive in the Esoteric File Archive: glass-0.7.tar.gz, whose files are all timestamped 22 October 2005, and glass-0.12.tar.bz2, timestamped 25 October 2005. Both are C++ programs of around two thousand lines, released under the GPL, and both READMEs consist of only a few lines pointing the reader at the esolangs wiki and explaining how to build the IRC bot. The specification has always lived on the wiki, not in the tarball.

Design Philosophy

The design has a single organising idea: push everything into methods.

Most languages, including most stack languages, give arithmetic special syntactic status. Forth has +. C has +. Even Smalltalk, the purest of the mainstream object languages, lets 3 + 4 read naturally by making + a binary message selector. Glass takes the position that if arithmetic is conceptually a method on a class, it should look like one - with no syntactic sugar, no shortcuts, and no exceptions.

So there is a built-in class A for arithmetic. To add, you instantiate A into a variable, push both operands, retrieve the function a from the instance, and invoke it. In Glass that reads:

(_a)A!<3><4>(_a)a.?

Reading left to right: push the name _a; A pushes the class name; ! pops both and creates a new instance of A in _a; <3> and <4> push numeric literals; (_a)a pushes an object name and a function name; . retrieves the bound method; ? calls it. Nine operations to compute 3 + 4.

The second organising idea is that names, not values, are the stack’s native currency. (x) pushes the name x, not its contents; * is the separate operator that dereferences a name to a value; = pops a name and a value and performs the assignment. This indirection is what makes the object system work with such a small command set - . can look up a method name in the callee’s class rather than the caller’s scope precisely because names are first-class stack citizens - and it is also the single largest source of confusion when reading Glass code.

Key Features

The command set

Glass has roughly a dozen commands, each one character long:

CommandEffect
(name)Push a variable name. Parentheses optional for a single letter
(number)Duplicate the stack element that many positions down to the top
<number>Push a numeric literal, integer or floating-point
"string"Push a string literal
'comment'A comment; not parsed, and not nestable
,Pop and discard
=Pop a name and a value; assign
!Pop a target name and a class name; instantiate, running the constructor
.Pop an object name and a function name; push the bound method
?Pop a bound method and execute it
*Pop a name; push its value
$Pop a name; assign the current object to it
^Return from the current function
/(name) ... \Loop while name holds a true value

Everything else - control flow beyond the while loop, comparison, string handling, all input and output - is a method call.

Four kinds of variable

Scope is encoded in the first character of a name, which is the one place Glass is genuinely economical rather than merely terse:

  • Uppercase initial: a global variable. Classes live here.
  • Lowercase initial, retrieved with .: a class-local variable, immutable, which is how methods are stored.
  • Lowercase initial, retrieved with *: an object-local variable - an instance field.
  • Leading underscore: local to the current function invocation. These always require parentheses.

Crucially, names resolve where they are used, not where they were written. Pass _a out of a function and into its caller, and it refers to the caller’s _a. This dynamic-scoping-by-name behaviour is what makes the . operator work, since a method name pushed by the caller is resolved in the callee class’s context. It is also a hazard, which is why the language provides class V to mint guaranteed-fresh global variable names on demand.

Built-in classes

Five classes are provided by the implementation:

ClassPurposeMethods
AArithmetica s m d mod f for add, subtract, multiply, divide, modulus, floor; e ne lt le gt ge for comparison
SStringsl length, i index, si set-index, a concatenate, d divide at position, e equality, ns number-to-character, sn character-to-number
VAutogenerated variablesn to mint a fresh global name, d to delete one
OOutputo for strings and names, on for numbers
IInputl for a line, c for a character, e to test end-of-input

Program structure

A program is a sequence of class definitions, {ClassName [methodName body] [methodName body]}. Three method names are special: c__ is the constructor, run on instantiation; d__ is a destructor, specified but not implemented by the reference interpreter and unused by any known program; and m in class M is the entry point. Execution begins as though the runtime had executed (_t)M!(_t)m.? - instantiate M, call its m.

Hello World is therefore a single class with a single method:

{M[m(_o)O!"Hello World!"(_o)o.?]}

Instantiate the output class O into _o, push the string, retrieve _o.o, call it. The specification follows this example with the line “Isn’t that easy?!”, which is the language’s entire attitude in three words.

An unformatted language

Glass ignores nothing and requires no whitespace, so real programs are published as dense character walls. The Fibonacci example on the wiki is only a few lines of unbroken punctuation. Chu-Carroll’s 2007 write-up makes the point that these programs become tractable the moment you insert line breaks between logical statements - the difficulty is presentational as much as semantic. Sam Coppini’s later interpreter turns that observation into a feature in both directions, offering a --minify flag that compresses readable Glass back down into the traditional wall.

Evolution

Glass has essentially not evolved. The two 2005 snapshots three days apart are the whole of the reference implementation’s history, and the specification on the wiki has been stable for many years. What movement there has been came from other people, twelve years later.

Sam Coppini’s C++17 interpreter, begun in August 2017, is the most substantial. Its documented departures from the reference implementation are worth listing because each one is a considered opinion about what Glass should have been:

  • Multiple inheritance, declared by naming parent classes after the child: {(Child)(Parent1)(Parent2)}. Earlier-named classes override later ones, and parent constructors run in reverse order of declaration.
  • Imports, by placing a filename as a bare string literal outside any class definition, so that Glass programs can span files.
  • Compilation to C89 via --compile, and minification via --minify.
  • A constructor fix: the reference interpreter does not run c__ when the initial instance of M is created; this one does.
  • No destructors, on the reasoning that a garbage-collected language with no external resources has nothing for d__ to do - and that the reference interpreter never implemented them either.

A --pedantic flag disables all of it, and --convert rewrites extended source back into standard Glass. A separate Rust compiler for Glass was started a month later in September 2017 and describes itself as a work in progress. Both repositories went quiet in 2021.

Current Relevance

Glass is dormant. There is no active development, no package ecosystem, and no user community distinct from the general esolangs readership. Its home page on codu.org no longer serves the interpreter, and the surviving distribution channel is the Esoteric File Archive on GitHub.

Its standing within esoterica, though, is high. Being selected as the esolangs featured language for May to October 2012 marks it as one of the specifications the community considers worth reading rather than merely worth laughing at, and its reported recurring appearance on “weirdest programming languages” lists has kept it in circulation far longer than most 2005 esolangs. That two people independently decided to reimplement it a dozen years after its release - one adding inheritance and a C backend, the other writing a compiler in Rust - says something about how much genuine structure there is to work with.

Anyone wanting to run it today has three options: build the 2005 C++ reference interpreter from the archive, build Coppini’s C++17 interpreter, or, where one is available, use an online esolang interpreter that supports Glass. No official Docker image exists for any of them.

Why It Matters

It makes the cost of an object system visible. Every language with objects pays for method dispatch: a lookup, a binding of the receiver, a call. Glass simply refuses to hide any of it. Writing (_a)A! before you can add, and (_a)a.? to actually add, is the same work your Java or Python runtime does on every + - it has just been moved from the implementation into the source text. That is a genuinely instructive thing for a language to do, and very few languages do it.

It is an argument about syntactic sugar. The reason 3 + 4 is not nine operations in Smalltalk is that Smalltalk provides binary selectors, and the reason it is not nine operations in Forth is that + is a primitive word. Glass removes both accommodations and lets the reader draw the conclusion. Sugar is not decoration; it is what makes a consistent semantic model habitable.

It demonstrates that unpleasantness and incoherence are different things. Glass is unpleasant to write by design, but the specification is precise enough that independent implementers could reproduce it, extend it with inheritance and imports, and compile it to C. Plenty of esoteric languages are hostile; comparatively few are hostile and rigorously enough defined to survive reimplementation.

It preserves a moment in esolang culture. An interpreter with an IRC bot build flag, a netcat invocation in the README, and a specification that ends its Hello World example with “Isn’t that easy?!” is a document of how these languages were made and shared in the mid-2000s: in a chat channel, for an audience of a few dozen people who found this funny.

Sources

Timeline

2005
Gregor Richards creates Glass. The esolangs article, which is the primary specification, dates the language to 2005 and the wiki files it under its 2005 category. Richards had already written several other esoteric languages, among them 2L, FukYorBrane and ORK
2005
Reference interpreter 0.7 is packaged. Every file inside the archived glass-0.7.tar.gz carries a timestamp of 22 October 2005. It is roughly 2,000 lines of C++ under the GPL, built around separate modules for parsing, classes, class instances, variables and the built-in classes
2005
Version 0.12 follows three days later; its file timestamps read 25 October 2005. The built-ins module grows noticeably between the two snapshots, and a fourth example program - cat.glass - joins hello_world, fibonacci and counter. No later reference version appears in the Esoteric File Archive
2007
Mark C. Chu-Carroll writes up Glass on the Good Math/Bad Math blog on 2 March 2007, under the title "Clear Object-Oriented Programming? Not in Glass". The post walks through Hello World, Fibonacci, 99 Bottles of Beer and a quine, and popularises the description of the language as a warped cross between Smalltalk and Forth
2012
Glass is chosen as the featured language on the esolangs wiki for the period from May to October 2012, a slot the wiki uses to highlight languages the community considers well specified and worth studying
2017
Two independent reimplementations appear within about five weeks of each other. Sam Coppini creates a C++17 interpreter on 9 August 2017 that adds multiple inheritance, imports across files, a minifier and a compiler to C89. A Rust compiler for Glass is started on 17 September 2017
2021
Both third-party projects see their last commits this year - April 2021 for the Rust compiler, October 2021 for the C++ interpreter - and the esolangs article's most recent substantive revision is dated 16 January 2021. Glass has been quiet since

Notable Uses & Legacy

A brainfuck interpreter written in Glass

The longest program published on the esolangs page is a complete brainfuck interpreter, written across three classes - a cell-band class, a control class holding the program text and tape, and the mandatory M. It is the standard proof that a language is usable rather than merely Turing complete on paper, and in Glass it required implementing tape movement, bracket matching and wrapping arithmetic entirely out of method calls on the built-in A and S classes

A self-reproducing quine

A two-line quine appears in the specification, working by pushing the program's own text as a string literal, using S.ns to reconstruct the double-quote character it cannot contain directly, and then replaying stack duplication commands to print the text twice. It is one of the shorter published quines for a language with no reflection facilities

The bundled IRC bot mode

The reference interpreter ships with glassIRC.sh and a build target enabled by compiling with -DIRC, turning the interpreter into an IRC bot that evaluates Glass sent to it over a channel. The README reportedly documents piping it into netcat against irc.freenode.net. It reflects where the language lived: the esolangs IRC community of the mid-2000s, alongside Richards's EgoBot and BF Joust tooling

Glass-to-C compilation

Sam Coppini's C++17 reimplementation doubles as a compiler, translating Glass source into C89-compatible C with the --compile flag. It also offers --minify to obfuscate a program by renaming variables to single characters, and --pedantic to switch its language extensions off and enforce the original specification

Teaching material for stack-machine and OO semantics

Because Glass keeps method dispatch, four distinct variable scopes and an explicit operand stack visible at every step, it is used in esolang writing and discussion as a compact worked example of what an object system costs when none of it is hidden by syntax

Language Influence

Influenced By

Running Today

Run examples using the official Docker image:

docker pull
Last updated: