πŸ₯ž FORTH STACK DIFFICULTY: Adept Behavioral

Iterator (Forth)

Walk the graveyard of memory, touching every tombstone.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Necromancy // Grave-Walking
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FORTH PATTERN //
\ Grave-Walking: The Iterator
\ Passing an XT to map over contiguous memory blocks.

CREATE SOUL-ARRAY 10 , 20 , 30 ,

: FOR-EACH-SOUL ( xt array len -- )
  0 ?DO
    DUP I CELLS + @   \ Fetch value
    OVER EXECUTE      \ Execute XT with value
  LOOP
  2DROP ;

: PURGE-SOUL ( val -- )
  ." Purging soul with essence " . CR ;

\ Usage:
\ ' PURGE-SOUL SOUL-ARRAY 3 FOR-EACH-SOUL

To traverse a collection in the deep stack, we don’t build complex object hierarchies. The Iterator accepts an array bounds and an Execution Token (XT). It traverses the pointers, invoking the spell against each isolated fragment of memory.

Runic Tags: #behavioral #iterator #forth #memory-walking