Anonymous user
Singleton: Difference between revisions
→{{header|Lasso}}: Singleton Examples
(→{{header|Vala}}: Singleton!) |
(→{{header|Lasso}}: Singleton Examples) |
||
Line 837:
document.write( (new Singleton()).get() );</lang>
=={{header|Lasso}}==
Lasso supports singletons on two levels.
==Server wide singleton==
<lang Lasso>// Define the thread if it doesn't exist
// New definition supersede any current threads.
not ::serverwide_singleton->istype
? define serverwide_singleton => thread {
data public switch = 'x'
}
local(
a = serverwide_singleton,
b = serverwide_singleton,
)
#a->switch = 'a'
#b->switch = 'b'
#a->switch // b</lang>
==Thread level singleton==
<lang Lasso>// Define thread level singleton
define singleton => type {
data public switch = 'x'
public oncreate => var(.type)->isa(.type) ? var(.type) | var(.type) := self
}
local(
a = singleton,
b = singleton,
)
#a->switch = 'a'
#b->switch = 'b'
#a->switch // b</lang>
=={{header|Logtalk}}==
|