RosettaCodeData/Task/Singleton/EMal/singleton.emal
2026-04-30 12:34:36 -04:00

17 lines
540 B
Text

type Singleton
model
text greeting
fun speak ← void by block do writeLine(me.greeting + " I'm a singleton") end
end
Singleton instance
fun getInstance ← Singleton by block
if instance æ null do instance ← Singleton() end
return instance
end
type SomeOtherType
Singleton s1 ← Singleton.getInstance()
s1.greeting ← "Hello"
Singleton s2 ← Singleton.getInstance()
s2.greeting.append(", World!")
writeLine(s1 + " and " + s2 + " are the same object: " + (s1 æ s2) + ", s2: " + s2.greeting)
s1.speak() # call instance method