🥞 FORTH STACK DIFFICULTY: Adept Behavioral

Visitor (Forth)

Dispatch an ethereal form to inspect the internal structures.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Ethereal-Projection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FORTH PATTERN //
\ Ethereal-Projection: The Visitor
\ Applying a dispatched XT over a typed entity.

\ Data structure: [TYPE] [VALUE]
CREATE ENTITY-1 1 , 100 ,
CREATE ENTITY-2 2 , 50 ,

: BUFF-VISITOR ( type val -- )
  SWAP 1 = IF
    ." Buffing Warrior. Str +10." CR DROP
  ELSE
    ." Buffing Mage. Int +10." CR DROP
  THEN ;

: ACCEPT-VISITOR ( entity-addr visitor-xt -- )
  SWAP DUP @ SWAP CELL+ @  ( xt type val )
  ROT EXECUTE ;

\ Usage:
\ ENTITY-1 ' BUFF-VISITOR ACCEPT-VISITOR
\ ENTITY-2 ' BUFF-VISITOR ACCEPT-VISITOR

When the structure of a dark construct cannot be modified, one must project an ethereal form inside. The Visitor takes the form of an Execution Token (XT), passed into the core memory of an object, reading its type-tag and applying arbitrary logic without altering the construct’s class definition.

Runic Tags: #behavioral #visitor #forth #ethereal