Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
17
Task/Singleton/Lasso/singleton-1.lasso
Normal file
17
Task/Singleton/Lasso/singleton-1.lasso
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// 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
|
||||
16
Task/Singleton/Lasso/singleton-2.lasso
Normal file
16
Task/Singleton/Lasso/singleton-2.lasso
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// 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
|
||||
22
Task/Singleton/Lingo/singleton.lingo
Normal file
22
Task/Singleton/Lingo/singleton.lingo
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- parent script "SingletonDemo"
|
||||
|
||||
property _instance
|
||||
property _someProperty
|
||||
|
||||
----------------------------------------
|
||||
-- @constructor
|
||||
----------------------------------------
|
||||
on new (me)
|
||||
if not voidP(me.script._instance) then return me.script._instance
|
||||
me.script._instance = me
|
||||
me._someProperty = 0
|
||||
return me
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- sample method
|
||||
----------------------------------------
|
||||
on someMethod (me, x)
|
||||
me._someProperty = me._someProperty + x
|
||||
return me._someProperty
|
||||
end
|
||||
4
Task/Singleton/Nim/singleton-1.nim
Normal file
4
Task/Singleton/Nim/singleton-1.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
type Singleton = object # Singleton* would export
|
||||
foo*: int
|
||||
|
||||
var single* = Singleton(foo: 0)
|
||||
4
Task/Singleton/Nim/singleton-2.nim
Normal file
4
Task/Singleton/Nim/singleton-2.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import singleton
|
||||
|
||||
single.foo = 12
|
||||
echo single.foo
|
||||
6
Task/Singleton/Oforth/singleton-1.oforth
Normal file
6
Task/Singleton/Oforth/singleton-1.oforth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Object Class new: Sequence(channel)
|
||||
Sequence method: initialize(initialValue)
|
||||
Channel newSize(1) := channel
|
||||
@channel send(initialValue) drop ;
|
||||
|
||||
Sequence method: nextValue @channel receive dup 1 + @channel send drop ;
|
||||
6
Task/Singleton/Oforth/singleton-2.oforth
Normal file
6
Task/Singleton/Oforth/singleton-2.oforth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import: parallel
|
||||
|
||||
: testSequence
|
||||
| s i |
|
||||
Sequence new(0) ->s
|
||||
100 loop: i [ #[ s nextValue println ] & ] ;
|
||||
21
Task/Singleton/Sidef/singleton.sidef
Normal file
21
Task/Singleton/Sidef/singleton.sidef
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Singleton(name) {
|
||||
static instance;
|
||||
|
||||
method new(name) {
|
||||
instance := Singleton.bless(Hash(:name => name));
|
||||
}
|
||||
method new {
|
||||
Singleton.new(nil);
|
||||
}
|
||||
}
|
||||
|
||||
var s1 = Singleton('foo');
|
||||
say s1.name; #=> 'foo'
|
||||
say s1.object_id; #=> '30424504'
|
||||
|
||||
var s2 = Singleton();
|
||||
say s2.name; #=> 'foo'
|
||||
say s2.object_id; #=> '30424504'
|
||||
|
||||
s2.name = 'bar'; # change name in s2
|
||||
say s1.name; #=> 'bar'
|
||||
Loading…
Add table
Add a link
Reference in a new issue