🥞 FORTH STACK DIFFICULTY: Adept Structural

Composite (Forth)

Treat the lone soul and the legion as one entity.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Swarm-Logic
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FORTH PATTERN //
\ Swarm-Logic: The Composite
\ A linked list or array of Execution Tokens (XTs).

CREATE SWARM 10 CELLS ALLOT
VARIABLE SWARM-COUNT
0 SWARM-COUNT !

: ADD-TO-SWARM ( xt -- )
  SWARM-COUNT @ CELLS SWARM + !
  1 SWARM-COUNT +! ;

: COMMAND-SWARM ( -- )
  SWARM-COUNT @ 0 ?DO
    I CELLS SWARM + @ EXECUTE
  LOOP ;

: SUMMON-RAT ( -- ) ." Squeak!" CR ;
: SUMMON-BAT ( -- ) ." Flap!" CR ;

\ Usage:
\ ' SUMMON-RAT ADD-TO-SWARM
\ ' SUMMON-BAT ADD-TO-SWARM
\ COMMAND-SWARM

To control a legion, one must issue a single command. The Composite stores arrays of Execution Tokens (XTs). Executing the composite word automatically unfolds across the recursive depths, triggering every chained entity.

Runic Tags: #structural #composite #forth #swarms