Arrays in Forth

Forth fans say “build your own arrays”—comments go wild

TLDR: Forth’s tutorial shows how to build your own arrays, from simple buffers to flexible multi-cell records, and even fixes a sample with a needed SWAP. Comments split over whether “unindexed arrays” are useful and whether indexing should start at zero or one, turning a lesson into lively debate.

In the Forth world, arrays aren’t a default—they’re a DIY project. The tutorial shows how to roll your own “indexed” arrays (pick an element) and “unindexed” arrays (basically a work buffer), then ups the ante with a flexible, long-element array for game rooms. But the comments? Pure spice. One reader immediately nitpicks the sample code, shouting that it needs a SWAP to index correctly, and the thread turns into a live code review. Another camp argues that unindexed arrays aren’t “arrays” at all, prompting eimrine’s blunt question: what inevitable use-cases even justify them?

Fans clap back with examples like scratch pads, I/O buffers, and ring buffers, while critics call this “make-your-own-everything” vibe intimidating for beginners. Then the classic brawl erupts: zero-based vs one-based indexing. The tutorial says “zero is first,” but traditionalists want “1 means 1,” joking you should define 101 elements and ignore the first—cue memes and eye-rolls.

Overall mood: Forth purists love the freedom and performance; casual learners want a standard “array” button. The drama lands somewhere between “choose your own adventure” and “why is the manual a puzzle book?” And yes, someone always posts “Remember, zero is the first element,” as if it’s on a T‑shirt anyway.

Key Points

  • Forth encourages defining custom data types rather than relying on standard array constructs.
  • Unindexed arrays allocate bytes at compile-time and return the origin address at run-time, functioning as buffers.
  • Indexed arrays map an index to the address of an equal-length element and commonly use CREATE/DOES> with cells.
  • Zero-based indexing is standard in Forth; the example array definition requires SWAP in DOES> to correctly compute addresses.
  • Multi-cell elements are supported via a long-element-array, and subfields can be accessed using defined offsets.

Hottest takes

"What are any inevitable use-cases of the unindexable array in Forth?" — eimrine
"The example for : array I think needs a 'SWAP'..." — anonymous
"Remember, zero is the first element" — thread meme
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.