Designing Angort: A Personal Programming Odyssey
Delving into the depths of modern programming languages during my C/C days, I questioned their intricacies, particularly garbage collection with cycle detection, and the elegance of first-class functions with full lexical closure. My quest for understanding led me to create a personal programming language that reflects my unique approach and journey. Let me introduce Angort, a quirky yet powerful creation with a random pair of syllables.
Angort: The Genesis
Angort was the result of my need to understand and explore the core mechanisms of programming languages. It began with a simple base: Forth. The simplicity of writing a byte-code Forth-like interpreter was immediate and gratifying. I then added local variables and parameters for my sanity, followed by collections with garbage collection, lists, and dictionaries. The introduction of anonymous functions and lexical closure solved the Funarg problem, a challenge that might seem obscure to the uninitiated but was a significant hurdle in my journey.
The Magic of Angort
Angort's syntax and semantics are as intriguing as they are powerful. The syntax for a list is typically denoted by `[itemitemitem…]`, but it isn't actually syntax in the conventional sense. The true magic is in the stack, where each element is manipulated and linked in a manner that makes the list construction both intuitive and efficient. For example, `[123]` is not a syntax but a series of stack operations: `[` pushes a new list, `1` pushes `1`, `]` pops `1` and appends it, repeating for `2` and `3`.
This unique approach opens up a world of possibilities. Python-style comprehensions are effortlessly integrated. For instance, to generate a list of the first 30 squares, the code is succinct and elegant:
[0 30 range each {i dup}]
And if we prefer using first-class functions, we could do:
[0 30 range dup map]
The first-class functions in Angort truly have closures, a feature that allows functions to retain their lexical environment. Consider the following simple counter example:
:mkcounter :a 0!a a dup 1!a
This function returns an anonymous function that, when called, increments a counter. Here's how it functions:
20 :mkcounter :a 0!a a dup 1!a 20 mkcounter !F 40 . 0 40 . 1 40 . 2
Angort in Action: Subsumption Architecture
When I was working on my final year undergraduate dissertation, I had to implement a Brooks subsumption system for a robot. The subsumption architecture, as defined on Subsumption architecture - Wikipedia, involves complex data flows and processing. Angort turned out to be a perfect fit. The elegance and flow of the language made the implementation a beautiful experience.
The deep understanding of Angort’s mechanisms and syntax allowed me to write and debug the code effortlessly. This experience solidified the idea that Angort is not just a quirky project but a powerful tool that suits my needs and workflows. Its ease of writing C plugins and the availability of native C libraries made it a versatile choice for my PhD work in data analysis and visualization.
Conclusion: Angort's Place in My Life
While not without its flaws, such as a few remaining bugs and deep-seated safety issues, Angort is a language that holds a special place in my heart. It is shaped by my unique approach and fits seamlessly into my broken, slightly elderly brain. Despite its age and shortcomings, it remains my favorite language because of its core values and the joy it brings to my work.