1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Primes example
// written in AjSharp
// (read more at http://en.wordpress.com/tag/ajsharp/)
// using Channels, go command, operators <- (a la go programming language)

numbers = new Channel();

running = true;
k = 1;

go while(running) { k++; numbers <- k; }

function filter(in, out, prime)
{
	while (true) 
	{
		value = <-in;
		if (value % prime)
			out <- value;
	}
}

function makefilter(channel, number)
{
	newchannel = new Channel();
	go filter(channel, newchannel, number);
	return newchannel;
}

channel = numbers;

number = <-channel;

while (number < 1000) 
{
	PrintLine("Prime " + number);
	
	channel = makefilter(channel, number);
	
	number = <-channel;
}

running = false;