Needed 1+1, built a functional programming language
Source Entity
Hacker News

A developer successfully turned a simple data structures assignment into a comprehensive project by building a functional programming language. The resulting language, graphLang, includes features like garbage collection, closures, and a custom memory allocator.
From Homework to Language Design: The graphLang Journey
What began as a foundational data structures assignment—converting an arithmetic expression into a binary tree—has evolved into a sophisticated exercise in language engineering. The developer’s objective was to evaluate the expression '1 + 1 + 1' by architecting a tree structure where operators serve as nodes and operands as leaves. This recursive approach to evaluation is a classic implementation of expression parsing, where the order of operations is dictated by the depth and hierarchy of the tree.
The Mechanics of Expression Evaluation
The core of the project relies on the recursive collapse of nodes. By treating the initial expression as a binary tree, the developer demonstrated how a simple '+' operator at the root requires the evaluation of its left and right children before the total sum can be realized. This process mirrors the underlying logic of compilers and interpreters, which must transform human-readable syntax into a structured format that a machine can process sequentially.
Beyond the Assignment: Scaling Complexity
While the primary task was limited to arithmetic, the developer expanded the scope significantly by implementing a functional programming language dubbed 'graphLang' using the C programming language. This transition from a simple evaluator to a full-fledged language environment demonstrates a deep understanding of low-level systems programming. By integrating a custom memory allocator and a garbage collector, the developer addressed the critical challenges of memory management that are inherent in languages like C.
Core Language Features
The inclusion of closures and a Foreign Function Interface (FFI) elevates graphLang from a toy project to a functional tool. Closures allow functions to maintain state and scope, a hallmark of functional programming paradigms, while the FFI provides the necessary bridge for the language to interact with external libraries or system-level code. These features are typically the most complex to implement, requiring a robust understanding of stack frames and heap management.
The Role of the REPL
By implementing a Read-Eval-Print Loop (REPL), the developer has provided a modern interface for interaction, allowing users to execute code snippets in real-time. This is a vital component for language development, as it facilitates rapid prototyping and debugging. The REPL serves as the primary gateway for users to test the recursive tree-evaluation logic that started the entire project.
Implications and Future Trends
This project serves as a testament to the power of 'over-engineering' as a pedagogical tool. By pushing past the constraints of a simple assignment, the developer has gained practical experience in the entire lifecycle of language creation. As the industry continues to prioritize memory safety and efficient execution, projects like graphLang highlight the enduring relevance of learning systems programming from the ground up, proving that even the most basic arithmetic problems can lead to significant technical innovation.