out = new(T, 100);
go func(in, out *T, f uint64) {
for {
- out -< f * <- in;
+ out <- f * <-in;
}
}(in, out, f);
return in, out;
for i := 0; i < len(OUT); i++ {
t := min(xs);
for i := 0; i < n; i++ {
- ins[i] -< x;
+ ins[i] <- x;
}
for i := 0; i < n; i++ {
func AsynchFifo() {
ch := new(chan int, N);
for i := 0; i < N; i++ {
- ch -< i
+ ch <- i
}
for i := 0; i < N; i++ {
if <-ch != i {
}
}
-func Chain(ch *chan<- int, val int, in *chan<- int, out *chan-< int) {
+func Chain(ch *<-chan int, val int, in *<-chan int, out *chan<- int) {
<-in;
if <-ch != val {
panic(val)
}
- out -< 1
+ out <- 1
}
// thread together a daisy chain to read the elements in sequence
go Chain(ch, i, in, out);
in = out;
}
- start -< 0;
+ start <- 0;
for i := 0; i < N; i++ {
- ch -< i
+ ch <- i
}
<-in
}
}
func i32sender(c *chan int32) {
- c -< 234
+ c <- 234
}
func i64receiver(c *chan int64) {
}
func i64sender(c *chan int64) {
- c -< 234567
+ c <- 234567
}
func breceiver(c *chan bool) {
}
func bsender(c *chan bool) {
- c -< true
+ c <- true
}
func sreceiver(c *chan string) {
}
func ssender(c *chan string) {
- c -< "hello again"
+ c <- "hello again"
}
func main() {
go i32receiver(c32);
pause();
- ok = c32 -< 123;
+ ok = c32 <- 123;
if !ok { panic("i32receiver") }
go i32sender(c32);
pause();
go i64receiver(c64);
pause();
- ok = c64 -< 123456;
+ ok = c64 <- 123456;
if !ok { panic("i64receiver") }
go i64sender(c64);
pause();
go breceiver(cb);
pause();
- ok = cb -< true;
+ ok = cb <- true;
if !ok { panic("breceiver") }
go bsender(cb);
pause();
go sreceiver(cs);
pause();
- ok = cs -< "hello";
+ ok = cs <- "hello";
if !ok { panic("sreceiver") }
go ssender(cs);
pause();
}
seqno++;
- in.req -< seqno;
+ in.req <- seqno;
release := new(chan int);
go dosplit(in, out, release);
dat := <-in.dat;
- out[0].dat -< dat;
+ out[0].dat <- dat;
if !both {
<-wait
}
<-out[1].req;
- out[1].dat -< dat;
- release -< 0;
+ out[1].dat <- dat;
+ release <- 0;
}
func split(in *dch, out *dch2){
release := new(chan int);
go dosplit(in, out, release);
- release -< 0;
+ release <- 0;
}
func put(dat item, out *dch){
<-out.req;
- out.dat -< dat;
+ out.dat <- dat;
}
func get(in *dch) item{
seqno++;
- in.req -< seqno;
+ in.req <- seqno;
return <-in.dat;
}
seqno++
select{
- case req[0] -< seqno:
+ case req[0] <- seqno:
dat[0] = in[0].dat;
req[0] = nil;
- case req[1] -< seqno:
+ case req[1] <- seqno:
dat[1] = in[1].dat;
req[1] = nil;
- case it <- dat[0]:
+ case it = <-dat[0]:
out[0] = it;
dat[0] = nil;
- case it <- dat[1]:
+ case it = <-dat[1]:
out[1] = it;
dat[1] = nil;
}
func copy(in *dch, out *dch){
for {
<-out.req;
- out.dat -< get(in);
+ out.dat <- get(in);
}
}
uv = get2(U,V);
switch end(uv[0])+2*end(uv[1]) {
case 0:
- Z.dat -< add(uv[0], uv[1]);
+ Z.dat <- add(uv[0], uv[1]);
case 1:
- Z.dat -< uv[1];
+ Z.dat <- uv[1];
copy(V,Z);
case 2:
- Z.dat -< uv[0];
+ Z.dat <- uv[0];
copy(U,Z)
case 3:
- Z.dat -< finis;
+ Z.dat <- finis;
}
}
}(U, V, Z);
<-Z.req;
u := get(U);
if end(u) != 0 { done = true }
- else { Z.dat -< mul(c,u) }
+ else { Z.dat <- mul(c,u) }
}
- Z.dat -< finis;
+ Z.dat <- finis;
}(c, U, Z);
return Z;
}
<-Z.req;
uv := get2(U,V);
if end(uv[0])!=0 || end(uv[1]) != 0 {
- Z.dat -< finis;
+ Z.dat <- finis;
} else {
- Z.dat -< mul(uv[0],uv[1]);
+ Z.dat <- mul(uv[0],uv[1]);
UU := Split(U);
VV := Split(V);
W := Add(Cmul(uv[0],VV[0]),Cmul(uv[1],UU[0]));
<-Z.req;
- Z.dat -< get(W);
+ Z.dat <- get(W);
copy(Add(W,Mul(UU[1],VV[1])),Z);
}
}(U, V, Z);
u = get(U);
if end(u) != 0 { done=true }
else {
- Z.dat -< mul(itor(int64(i)),u);
+ Z.dat <- mul(itor(int64(i)),u);
<-Z.req;
}
}
}
- Z.dat -< finis;
+ Z.dat <- finis;
}(U, Z);
return Z;
}
<-Z.req;
u := get(U);
if end(u) != 0 { done= true }
- Z.dat -< mul(i2tor(1,int64(i)),u);
+ Z.dat <- mul(i2tor(1,int64(i)),u);
}
- Z.dat -< finis;
+ Z.dat <- finis;
}(c, U, Z);
return Z;
}
ZZ:=mkPS2();
<-Z.req;
z := inv(get(U));
- Z.dat -< z;
+ Z.dat <- z;
split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ);
copy(ZZ[1],Z);
}(U, Z);
VV := Split(V);
<-Z.req;
u := get(U);
- Z.dat -< u;
+ Z.dat <- u;
if end(u) == 0 {
if end(get(VV[0])) != 0 { put(finis,Z); }
else { copy(Mul(VV[0],Subst(U,VV[1])),Z); }
for {
<-Z.req;
u := get(U);
- Z.dat -< mul(u, c);
+ Z.dat <- mul(u, c);
c = mul(c, c0);
if end(u) != 0 {
- Z.dat -< finis;
+ Z.dat <- finis;
break;
}
for i := 1; i < n; i++ {
<-Z.req;
- Z.dat -< zero;
+ Z.dat <- zero;
}
}
}(U, Z, c0, n);
package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
-func Generate(ch *chan-< int) {
+func Generate(ch *chan<- int) {
for i := 2; ; i++ {
- ch -< i // Send 'i' to channel 'ch'.
+ ch <- i // Send 'i' to channel 'ch'.
}
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
-func Filter(in *chan<- int, out *chan-< int, prime int) {
+func Filter(in *<-chan int, out *chan<- int, prime int) {
for {
i := <-in // Receive value of new variable 'i' from 'in'.
if i % prime != 0 {
- out -< i // Send 'i' to channel 'out'.
+ out <- i // Send 'i' to channel 'out'.
}
}
}
// The prime sieve: Daisy-chain Filter processes together.
-func Sieve(primes *chan-< int) {
+func Sieve(primes *chan<- int) {
ch := new(chan int); // Create a new channel.
go Generate(ch); // Start Generate() as a subprocess.
for {
prime := <-ch;
- primes -< prime;
+ primes <- prime;
ch1 := new(chan int);
go Filter(ch, ch1, prime);
ch = ch1
func main() {
primes := new(chan int);
go Sieve(primes);
- if <-primes != 2 { panic(2) }
- if <-primes != 3 { panic(3) }
- if <-primes != 5 { panic(5) }
- if <-primes != 7 { panic(7) }
- if <-primes != 11 { panic(11) }
- if <-primes != 13 { panic(13) }
- if <-primes != 17 { panic(17) }
- if <-primes != 19 { panic(19) }
- if <-primes != 23 { panic(23) }
- if <-primes != 29 { panic(29) }
- if <-primes != 31 { panic(31) }
- if <-primes != 37 { panic(37) }
- if <-primes != 41 { panic(41) }
- if <-primes != 43 { panic(43) }
- if <-primes != 47 { panic(47) }
- if <-primes != 53 { panic(53) }
- if <-primes != 59 { panic(59) }
- if <-primes != 61 { panic(61) }
- if <-primes != 67 { panic(67) }
- if <-primes != 71 { panic(71) }
- if <-primes != 73 { panic(73) }
- if <-primes != 79 { panic(79) }
- if <-primes != 83 { panic(83) }
- if <-primes != 89 { panic(89) }
- if <-primes != 97 { panic(97) }
+ a := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
+ for i := 0; i < len(a); i++ {
+ if <-primes != a[i] { panic(a[i])}
+ }
sys.exit(0);
}
package main
// Send the sequence 2, 3, 4, ... to channel 'ch'.
-func Generate(ch *chan-< int) {
+func Generate(ch *chan<- int) {
for i := 2; ; i++ {
- ch -< i // Send 'i' to channel 'ch'.
+ ch <- i // Send 'i' to channel 'ch'.
}
}
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
-func Filter(in *chan<- int, out *chan-< int, prime int) {
+func Filter(in *<-chan int, out *chan<- int, prime int) {
for {
i := <-in // Receive value of new variable 'i' from 'in'.
if i % prime != 0 {
- out -< i // Send 'i' to channel 'out'.
+ out <- i // Send 'i' to channel 'out'.
}
}
}