langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,14 @@
#directory "+threads"
#load "unix.cma"
#load "threads.cma"
let sleepy_print msg =
Unix.sleep (Random.int 4);
print_endline msg
let threads =
List.map (Thread.create sleepy_print) ["Enjoy"; "Rosetta"; "Code"]
let () =
Random.self_init ();
List.iter (Thread.join) threads

View file

@ -0,0 +1,27 @@
bundle Default {
class MyThread from Thread {
New(name : String) {
Parent(name);
}
method : public : Run(param : Base) ~ Nil {
string := param->As(String);
string->PrintLine();
}
}
class Concurrent {
New() {
}
function : Main(args : System.String[]) ~ Nil {
t0 := MyThread->New("t0");
t1 := MyThread->New("t1");
t2 := MyThread->New("t2");
t0->Execute("Enjoy"->As(Base));
t1->Execute("Rosetta"->As(Base));
t2->Execute("Code"->As(Base));
}
}
}

View file

@ -0,0 +1,5 @@
for Msg in ["Enjoy" "Rosetta" "Code"] do
thread
{System.showInfo Msg}
end
end

View file

@ -0,0 +1,17 @@
void
foo()
{
if (pari_daemon()) {
// Original
if (pari_daemon()) {
// Original
pari_printf("Enjoy\n");
} else {
// Daemon #2
pari_printf("Code\n");
}
} else {
// Daemon #1
pari_printf("Rosetta\n");
}
}

View file

@ -0,0 +1,2 @@
my @words = <Enjoy Rosetta Code>;
@words».say

View file

@ -0,0 +1,3 @@
Rosetta
Code
Enjoy

View file

@ -0,0 +1,11 @@
int main() {
// Start threads and wait for them to finish
({
Thread.Thread(write, "Enjoy\n"),
Thread.Thread(write, "Rosetta\n"),
Thread.Thread(write, "Code\n")
})->wait();
// Exit program
exit(0);
}

View file

@ -0,0 +1,8 @@
int main(int argc, array argv)
{
call_out(write, random(1.0), "Enjoy\n");
call_out(write, random(1.0), "Rosetta\n");
call_out(write, random(1.0), "Code\n");
call_out(exit, 1, 0);
return -1; // return -1 starts the backend which makes Pike run until exit() is called.
}

View file

@ -0,0 +1,26 @@
Global mutex = CreateMutex()
Procedure Printer(*str)
LockMutex(mutex)
PrintN( PeekS(*str) )
UnlockMutex(mutex)
EndProcedure
If OpenConsole()
LockMutex(mutex)
thread1 = CreateThread(@Printer(), @"Enjoy")
thread2 = CreateThread(@Printer(), @"Rosetta")
thread3 = CreateThread(@Printer(), @"Code")
UnlockMutex(mutex)
WaitThread(thread1)
WaitThread(thread2)
WaitThread(thread3)
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf
FreeMutex(mutex)

View file

@ -0,0 +1,10 @@
[ 'Enjoy' 'Rosetta' 'Code' ] as $words
thread talker
$words pop "%s\n"
repeat dup print
500 choose ms
talker as a
talker as b
talker as c

View file

@ -0,0 +1,6 @@
Main(0,0)
|:
Print["Enjoy"]
Print["Rosetta"]
Print["Code"]
:|

View file

@ -0,0 +1 @@
(echo "Enjoy" & echo "Rosetta"& echo "Code"&)

View file

@ -0,0 +1,26 @@
Imports System.Threading
Module Module1
Public rnd As New Random
Sub Main()
Dim t1 As New Thread(AddressOf Foo)
Dim t2 As New Thread(AddressOf Foo)
Dim t3 As New Thread(AddressOf Foo)
t1.Start("Enjoy")
t2.Start("Rosetta")
t3.Start("Code")
t1.Join()
t2.Join()
t3.Join()
End Sub
Sub Foo(ByVal state As Object)
Thread.Sleep(rnd.Next(1000))
Console.WriteLine(state)
End Sub
End Module