Essential insights from Hacker News discussions

Show HN: I built a minimal Forth-like stack interpreter library in C

Here's a summary of the themes from the Hacker News discussion about Forth-like languages and interpreters:

Interest in Forth-Like Languages and Implementations

There's a clear and recurring interest in building and understanding Forth-like languages and their interpreters. Several users are actively working on or have recently created their own implementations.

  • ** Aynı zamanda** mentions writing an interpreter for a similar stack-based language and a compiler to x86 assembly for use as an intermediate language for a C compiler. They link to their GitHub project: "For more information see: https://github.com/FransFaase/MES-replacement" and their interpreter: "For the interpreter have a look at: stack_c_interpreter.c". They also shared a talk about their work: "At WHY2025, I gave a talk about the reasons why am working on this. See: https://www.youtube.com/watch?v=akzyyO5wvm0".
  • bertili notes a recent thread on similar topics, highlighting that "Another thread on small forth interpreters from just 15 days ago: https://news.ycombinator.com/item?id=45039301".
  • acidx reports writing a Forth interpreter in C using tail calls and CPS for efficiency, intended for an art project executing "Forth Haikus." They share their post: "I recently wrote one, in C, using tail calls to implement dispatch with CPS: https://tia.mat.br/posts/2025/08/30/forth-haiku.html".
  • vdupras sees the presented experiment as a "good tool to grok stack mechanics," but also points to other essential Forth elements and links to their own informative articles: "I wrote a series of articles that can help in that kind of discovery: http://tumbleforth.hardcoded.net/".

Technical Implementation Details and Efficiency

Discussions delve into specific technical approaches for implementing Forth interpreters, with a focus on efficiency and modern C/C++ techniques.

  • bertili suggests that Forth can be efficiently implemented in portable C++ using Continuation-Passing Style (CPS) with the musttail attribute in Clang, referencing the "Tails" project as an example: "Forth can be beautifully and efficiently implemented in portable c++ using the using continuation passing style via the clang musttail attribute. Have a look at Tails (not my project): [1] https://github.com/snej/tails".
  • acidx specifically mentions using tail calls with CPS for their C implementation to achieve efficiency for their art project.
  • The concept of "header-only libraries" is brought up as a valid model for C libraries, offering convenience for users. zoezoezoezoe defends this approach: "technically, "header only libraries" can be exceptions to C code not being in header files. See STB as an example https://github.com/nothings/stb. The advantage theoretically is that you can #include this library and use its code and types from just one file, its a decent model IMHO, but it can be jarring to someone unfamiliar with header only libraries."

Educational Resources and Foundational Concepts

Several users recommend learning resources and emphasize foundational programming concepts that are crucial for understanding Forth and low-level systems.

  • tdeck recommends two classic books for learning about Forth: "Starting FORTH" and "Threaded Interpretive Languages." They highlight the value of the latter for its bottom-up approach, even without mentioning Forth: "If you're interested in learning more about how FORTH works I, I can recommend two very old books. Starting FORTH https://archive.org/details/LeoBrodieStartingFORTHIntroducti... Threaded Interpretive Languages https://archive.org/details/R.G.LoeligerThreadedInterpretive... The latter doesn't even mention FORTH, and describes some very archaic CPU architectures, but I found it fascinating because it builds things from the ground up."
  • elcritch emphasizes the educational value of understanding different interpreter types (threaded, sub-routine) and the fundamental idea that "everything, even code, is really just numbers."
  • vdupras points out that stack mechanics are only one part of Forth, recommending study of "colon definition and immediateness" to fully grasp the language.

Code Review and Suggestions

Some participants offer constructive feedback and practical suggestions on the code presented in the original post or related projects.

  • gabrielsroka provides a numbered list of suggestions, including the importance of adding URLs to posts, correct code indentation on HN, clarifying the presence of a REPL, proper header file practices (code in .c files), and organizing usage code into separate .c files. They demonstrate correct formatting for code examples: "1. You should add a URL when you you create a post on HN. You can indent code two spaces on HN, eg: c Stack s; stack_init(&s); dict_init(); exec(&s, "10 20 + ."); // Prints \"30\" exec(&s, "1 2 3 4 .s"); // Shows stack contents

    1. Your readme mentions a repl but I don't see it in the source code.
    2. I'm not an expert in C but I thought header files shouldn't have code in them. The code should be in a .c file
    3. Maybe move the code from USAGE into its own .c file. ```c #include \"stacklib.h\"

    int main() { Stack s; stack_init(&s); dict_init(); exec(&s, "10 20 + ."); printf(\"\n\"); return 0; } ```"