A web framework written in (G)Forth
I'm not really sure where I got this idea from.
There's an article called "My history with Forth & stack machines", I read it many years ago. The author talks about their experience discovering, implementing, and, finally, using the Forth programming language. The cool thing about Forth is that it's incredibly simple: you start from a very simple foundation, and you keep adding new features using Forth itself. That's how comments are implemented, that's how flow control is implemented.
My history with Forth & stack machines
It's magical.
Forth is a stack-based programming language. Programming in Forth feels to me like solving many small puzzles: you put things in the stack, you remove them, you swap them, you duplicate them. Functions have to be simple, and do one thing, otherwise the stack operations can get complicated quickly.
A few years before that article was published I wrote a small game in Python, "Johnny saves the world", where a robot had to traverse a dangerous maze. The robot had a stack, and it would follow the instructions in the stack, one-by-one, in order to navigate the maze. The player was responsible for programming the robot, but there was one catch: the stack was limited in size. Fortunately, the robot could pick up new instructions in the maze, and add them to its stack, allowing it to traverse the whole maze while avoiding the evil robots.
⁂
And speaking of stacks, I feel very tired of the modern frontend stack. There are so many layers of complexity, so many abstractions and dependencies. Over the years I've been focusing more and more on backend, even though I love data visualization and thinking about user experiences. When I have to write frontend code I try to use vanilla Javascript, or micro-frameworks. My previous blog ran a SQL database on the browser itself, so that all frontend code was Javascript reading and writing to a database. For years I've been looking for different ways of writing websites.
So, one day I asked myself:
What if I could use Forth to program websites?
I had been playing with WebAssembly and it was liberating. If I could run a full database on the browser, what else could I do? I knew Forth was simple, and I was looking for simplicity, so I considered writing a Forth interpreter in WebAssembly. Each page would be a small program, with access to local storage and an append-only log for persistency. The more I thought about it, the more I liked the idea: it was weird, fun, and I would never have to write Javascript again. I was sold.

⁂
But if simplicity was the goal, why use WebAssembly at all? I decided to go with the simplest solution that would work. Each page is a Forth program that, when executed, produces HTML. That's it. But it's not a static site generator. The programs can read from and write to an append-only log. The log is handled by a Forth script running as a CGI script, and the script recompiles the necessary pages when a new recorded is added. No Javascript is needed, though it offers a better experience. With this, my blog can have comments and likes, and also some other fun ideas I have for the future.
It works; if you're reading this, it's live. There's still a lot to improve. I want to make the DSL more expressive and composable, but I know that will come with time. And I have ideas on how to automatically generate the index on the front page, for example. But to be honest I've been having fun with manually editing the pages. Pages! My site is, once again, made of pages, and not entries in a database. Things spill over each other. It's a garden, not a series of potted plants.
comment