🔮 JULIA ASTROMANCY DIFFICULTY: Adept Creational

Singleton

Tap into universal constants efficiently via the Singleton pattern in Julia.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Universal // Fundamental Forces
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JULIA PATTERN //
# Singleton in Julia: The Universal Constants
mutable struct UniversalTome
    gravitational_constant::Float64
    speed_of_light::Float64
end

# Use a const reference to hold the singleton instance
const THE_TOME = UniversalTome(6.67430e-11, 299792458.0)

# Accessor function to get the instance
function get_tome()
    return THE_TOME
end

# Usage
tome1 = get_tome()
tome2 = get_tome()
# tome1 === tome2 evaluates to true
Runic Tags: #creational #singleton #julia #astromancy