HeadlinesBriefing favicon HeadlinesBriefing.com

Building a Functional Language from a Data Structures Assignment

Hacker News •
×

A developer was given a data structures problem of evaluating 1+1+1 using a binary tree. Naturally, they decided to build an evaluator. What started as a simple assignment quickly evolved into a full programming language implementation in C.

The journey began with implementing closures, a garbage collector, a custom memory allocator, a REPL, and an FFI. The core challenge was representing arithmetic operations without hardcoding every operator case. By abstracting operations as generic functions, the evaluator only needed to know how to apply a function, not what it did.

Variables were added via a hash table lookup, though implementing this in C required writing a custom hash table from scratch. The project then shifted focus to memory optimization. Standard malloc overhead made node allocation expensive, prompting the creation of an arena allocator—a large pre-allocated memory block freed all at once.

This approach dramatically reduced overhead compared to individual allocations. The language, graph Lang, demonstrates how a simple academic exercise can spiral into a comprehensive language project involving memory management, type systems, and runtime infrastructure.