Forge: A Forth-Inspired Stack-Based Language for the Modern Web

The modern web development landscape is dominated by complex frameworks and verbose markup. However, a new experimental project called Forge seeks to challenge this paradigm by applying the principles of Forth—a stack-based, postfix language—to the creation of websites.

By treating HTML generation as a series of stack operations, Forge offers a minimalist approach to building pages that is as much an exercise in linguistic curiosity as it is a functional tool for web authoring.

The Core Concept: Postfix Web Development

At its heart, Forge is a stack-based language. In a traditional language, you might call a function with arguments in parentheses; in Forge, you push data onto a stack and then call a "word" (the Forth term for a function) that consumes that data.

For example, creating a simple header in Forge looks like this:

: h1  ( s -- )  "<h1>" emit  .  "</h1>" emit ;

"Hello, World!" h1

In this snippet, the : defines a new word h1. The ( s -- ) is a comment indicating the word takes a string from the stack and returns nothing. The . word prints the top item of the stack, while emit sends a string directly to the output. When the user calls "Hello, World!" h1, the string is pushed to the stack, and h1 consumes it, wrapping it in HTML tags.

Building Complex Structures with DSLs

One of the primary strengths of a stack-based model is its utility in creating Domain Specific Languages (DSLs). As noted by community members, Forth's postfix model is "genuinely underrated for DSL design."

Forge leverages this to simplify the implementation of microformats. Instead of writing repetitive HTML boilerplate, the author created a library of words to handle structured data:

: post-body
  h-entry-start
    "<p class='byline'>" emit
      "2026-05-21T14:00:00Z"  "May 21, 2026"  dt-published
      " · by " emit
      "Beto"  "/about"  p-author
    "</p>" emit
  h-entry-end

  "On building a tiny stack-based web language." p-summary
  "post-content"                                 e-content
  "/hello-world"  "permalink"                    u-url ;

"Hello, world!" "post-body" blog-post

By defining words like dt-published and p-author, the developer can create a high-level language tailored specifically to the needs of a blog, reducing the noise of raw HTML tags.

Hybrid Rendering Architecture

Forge isn't just a language; it's a complete runtime environment. A single binary manages the site, which consists of a library of words (lib.forge), a stylesheet (style.css), and a collection of .forge pages.

To balance SEO and user experience, Forge employs a hybrid rendering strategy:

  1. Server-Side Rendering (SSR): When a crawler or a first-time visitor hits a page, the backend compiler generates the HTML and serves it. This ensures that the source code is readable by search engines and WebMentions.
  2. Client-Side Rendering (CSR): Once the site is loaded, a service worker intercepts subsequent network requests. When a user navigates to a new page (e.g., /notes), the service worker fetches the .forge source and compiles it to HTML on the fly within the browser using WebAssembly.

This architecture provides the speed and feel of a Single Page Application (SPA) without sacrificing the accessibility of a static site.

State and Persistence

Forge handles interactivity through a simple, append-only log system. Rather than managing complex databases, the language allows developers to persist data to localStorage or a server-side log.

Consider a "like" button implementation:

: like-button  ( -- )
    "❤"  "do-like"  on-click ;

: do-like
  "1" "likes:demo" log-append ;

When the button is clicked, the value "1" is appended to the topic "likes:demo" in a JSONL (JSON Lines) file on the server. This minimalist approach to state management avoids the overhead of traditional API endpoints and database schemas.

Final Thoughts

While Forge may be "weird," as the author admits, it represents a fascinating exploration of how alternative programming paradigms can influence web development. By combining the efficiency of a stack-based language with the power of WebAssembly and a hybrid rendering model, Forge demonstrates that the web can be a place for experimental, lightweight, and highly customizable authoring tools.

Sources