{"slug": "a-forth-inspired-language-for-writing-websites", "title": "A Forth-inspired language for writing websites", "summary": "The article describes Forge, a stack-based programming language inspired by Forth, designed specifically for writing websites. It compiles to HTML on both the server and client side, enabling server-side rendering for crawlers and client-side rendering for a single-page application experience. The language supports features like persistent state through localStorage and an append-only server log, allowing for interactive elements such as like buttons.", "body_md": "A Forth-inspired language for writing websites\nI don't remember where the idea came from, but I decided that it would be cool if I could write websites using a stack-based language. Something like this:\n: h1 ( s -- ) \"<h1>\" emit . \"</h1>\" emit ;\n\"Hello, World!\" h1\nSo I wrote Forge.\nI quickly built a library of word definitions that let me easily add microformats to the HTML:\n: post-content\n\"Hello, world! This is my first post with Forge!\" p ;\n: post-body\nh-entry-start\n\"<p class='byline'>\" emit\n\"2026-05-21T14:00:00Z\" \"May 21, 2026\" dt-published\n\" · by \" emit\n\"Beto\" \"/about\" p-author\n\"</p>\" emit\nh-entry-end\n\"On building a tiny stack-based web language.\" p-summary\n\"post-content\" e-content\n\"/hello-world\" \"permalink\" u-url ;\n\"Hello, world!\" \"post-body\" blog-post\nEach site is a collection of pages, a library of words, and a stylesheet:\nmy-site\n├── lib.forge\n├── style.css\n└── pages\n├── about.forge\n├── hello.forge\n└── notes.forge\nA single binary runs the website:\nforge --log forge.log my-site/\nThe binary does a lot. It has a webassembly compiler that generates HTML from .forge\nfiles. When you visit a page the compiler runs on the backend, and you get the actual HTML in the source code, as well as the original .forge\nsource. But when you navigate between pages, a service worker captures the network request to the page, say, /notes\n, fetches the source /notes.forge\n), and builds the HTML on the fly by running the compiler on the browser. So we have server-side rendering for crawlers and WebMentions, and client-side rendering for a SPA experience.\nI love the limitations of the language. You can persiste things to state, localStorage, or to an append-only log on the server. For example example, I can add a \"like\" button to posts like this:\n: like-button ( -- )\n\"❤\" \"do-like\" on-click ;\n: do-like\n\"1\" \"likes:demo\" log-append ;\n: body\n\"I liked this!\" p\nlike-button ;\nWhen you click it, appends the value \"1\" to the topic \"likes:demo\" in the log. It's just JSONL (one JSON document per line). Forms can submit to other .forge\npages, and they simply put the contents in the stack for them. It's up to the target to use log-append\nto store in the backend.\nI like how weird it is. I might use it for my site, who knows? For now I'm just exploring some ideas.", "url": "https://wpnews.pro/news/a-forth-inspired-language-for-writing-websites", "canonical_source": "https://robida.net/entries/2026/05/21/a-forth-inspired-language-for-writing-websites", "published_at": "2026-05-22 15:00:50+00:00", "updated_at": "2026-05-22 16:07:15.228378+00:00", "lang": "en", "topics": ["developer-tools", "open-source", "web3"], "entities": ["Forth", "Forge", "Beto", "WebAssembly"], "alternates": {"html": "https://wpnews.pro/news/a-forth-inspired-language-for-writing-websites", "markdown": "https://wpnews.pro/news/a-forth-inspired-language-for-writing-websites.md", "text": "https://wpnews.pro/news/a-forth-inspired-language-for-writing-websites.txt", "jsonld": "https://wpnews.pro/news/a-forth-inspired-language-for-writing-websites.jsonld"}}