The Singleton of Snobol
Ensuring only one instance of a magical entity exists across the script.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Sealing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SNOBOL PATTERN //
* Singleton Pattern in SNOBOL4
DEFINE('GET_GRIMOIRE()')
GRIMOIRE_INSTANCE = ''
BOOK1 = GET_GRIMOIRE()
BOOK2 = GET_GRIMOIRE()
OUTPUT = BOOK1
OUTPUT = BOOK2
:(END)
GET_GRIMOIRE
IDENT(GRIMOIRE_INSTANCE, '') :F(HAS_GRIM)
GRIMOIRE_INSTANCE = 'The One True Grimoire'
HAS_GRIM
GET_GRIMOIRE = GRIMOIRE_INSTANCE :(RETURN)
END
To bind a Singleton in SNOBOL, one must check the void. Only if the essence is empty does the conjuration proceed; otherwise, the previously bound essence is returned intact.
Runic Tags:
#snobol
#creational
#singleton