]> Cypherpunks repositories - gostls13.git/commitdiff
make the tutorial programs run again.
authorRob Pike <r@golang.org>
Tue, 6 Jan 2009 23:49:27 +0000 (15:49 -0800)
committerRob Pike <r@golang.org>
Tue, 6 Jan 2009 23:49:27 +0000 (15:49 -0800)
(the text still needs fixing)
add the tutorial programs to the test run.

R=rsc
DELTA=41  (6 added, 0 deleted, 35 changed)
OCL=22174
CL=22174

doc/progs/cat.go
doc/progs/cat_rot13.go
doc/progs/fd.go
doc/progs/helloworld3.go
doc/progs/run
doc/progs/server.go
doc/progs/server1.go
doc/progs/sieve.go
doc/progs/sieve1.go
src/run.bash

index 993f9d59c6c04520674082c1072f5f0f053313ff..f74faf4f109e8f822a67c140038a8243e36b0cc4 100644 (file)
@@ -13,14 +13,14 @@ func cat(fd *FD.FD) {
        const NBUF = 512;
        var buf [NBUF]byte;
        for {
-               switch nr, er := fd.Read(&buf); true {
+               switch nr, er := fd.Read(buf); true {
                case nr < 0:
                        print("error reading from ", fd.Name(), ": ", er, "\n");
                        sys.exit(1);
                case nr == 0:  // EOF
                        return;
                case nr > 0:
-                       if nw, ew := FD.Stdout.Write((&buf)[0:nr]); nw != nr {
+                       if nw, ew := FD.Stdout.Write(buf[0:nr]); nw != nr {
                                print("error writing from ", fd.Name(), ": ", ew, "\n");
                        }
                }
index a8c570add6cc3e87a204faa7e25e8b78d3610bcb..1ef0f644340edf81e93a66af74f37e091b2ccd60 100644 (file)
@@ -22,7 +22,7 @@ func rot13(b byte) byte {
 }
 
 type Reader interface {
-       Read(b *[]byte) (ret int64, errno int64);
+       Read(b []byte) (ret int64, errno int64);
        Name() string;
 }
 
@@ -36,7 +36,7 @@ func NewRot13(source Reader) *Rot13 {
        return r13
 }
 
-func (r13 *Rot13) Read(b *[]byte) (ret int64, errno int64) {
+func (r13 *Rot13) Read(b []byte) (ret int64, errno int64) {    // TODO: use standard Read sig?
        r, e := r13.source.Read(b);
        for i := int64(0); i < r; i++ {
                b[i] = rot13(b[i])
@@ -57,14 +57,14 @@ func cat(r Reader) {
                r = NewRot13(r)
        }
        for {
-               switch nr, er := r.Read(&buf); {
+               switch nr, er := r.Read(buf); {
                case nr < 0:
                        print("error reading from ", r.Name(), ": ", er, "\n");
                        sys.exit(1);
                case nr == 0:  // EOF
                        return;
                case nr > 0:
-                       nw, ew := FD.Stdout.Write((&buf)[0:nr]);
+                       nw, ew := FD.Stdout.Write(buf[0:nr]);
                        if nw != nr {
                                print("error writing from ", r.Name(), ": ", ew, "\n");
                        }
index 9ec7d549380b3a64113c661a16a2bf4a116371ab..76b784f832dbe226f51fefe14438e8bc5cfde011 100644 (file)
@@ -41,7 +41,7 @@ func (fd *FD) Close() int64 {
        return 0
 }
 
-func (fd *FD) Read(b *[]byte) (ret int64, errno int64) {
+func (fd *FD) Read(b []byte) (ret int64, errno int64) {
        if fd == nil {
                return -1, Syscall.EINVAL
        }
@@ -49,7 +49,7 @@ func (fd *FD) Read(b *[]byte) (ret int64, errno int64) {
        return r, e
 }
 
-func (fd *FD) Write(b *[]byte) (ret int64, errno int64) {
+func (fd *FD) Write(b []byte) (ret int64, errno int64) {
        if fd == nil {
                return -1, Syscall.EINVAL
        }
index 2347a1a19eb291e6f2715faca529542685c3cc80..f282bcefb485992791b4f1ade56c62cee3812f90 100644 (file)
@@ -8,7 +8,7 @@ import FD "fd"
 
 func main() {
        hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'};
-       FD.Stdout.Write(&hello);
+       FD.Stdout.Write(hello);
        fd,  errno := FD.Open("/does/not/exist",  0,  0);
        if fd == nil {
                print("can't open file; errno=",  errno,  "\n");
index 489cab5bd91952959753c89d2903e1434717232d..e04c1031e632905f1d829a5fbfaa1a4af7370601 100755 (executable)
@@ -27,7 +27,7 @@ done
 
 function testit {
        6l $1.6
-       x=$(echo $(6.out $2 2>&1))  # extra echo canonicalizes
+       x=$(echo $(./6.out $2 2>&1))  # extra echo canonicalizes
        if [ "$x" != "$3" ]
        then
                echo $1 failed: '"'$x'"' is not '"'$3'"'
@@ -36,7 +36,7 @@ function testit {
 
 function testitpipe {
        6l $1.6
-       x=$(echo $(6.out | $2 2>&1))  # extra echo canonicalizes
+       x=$(echo $(./6.out | $2 2>&1))  # extra echo canonicalizes
        if [ "$x" != "$3" ]
        then
                echo $1 failed: '"'$x'"' is not '"'$3'"'
@@ -63,3 +63,5 @@ testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
 
 # server hangs; don't run it
 testit server1 "" ""
+
+rm -f 6.out *.6
index ea089785d94006ca8d0925c278eab7b84ed5c508..7a21e4396384beacd5b41b7d3c5118a0fb0f55e8 100644 (file)
@@ -6,7 +6,7 @@ package main
 
 type Request struct {
        a, b    int;
-       replyc  *chan int;
+       replyc  chan int;
 }
 
 type BinOp (a, b int) int;
@@ -16,14 +16,14 @@ func Run(op *BinOp, request *Request) {
        request.replyc <- result;
 }
 
-func Server(op *BinOp, service *chan *Request) {
+func Server(op *BinOp, service chan *Request) {
        for {
                request := <-service;
                go Run(op, request);  // don't wait for it
        }
 }
 
-func StartServer(op *BinOp) *chan *Request {
+func StartServer(op *BinOp) chan *Request {
        req := new(chan *Request);
        go Server(op, req);
        return req;
index d70ddfd9d0fa0519df318b15928511b19891ead3..b7e489d46dda51893454055a05bb92176e2f5c20 100644 (file)
@@ -6,7 +6,7 @@ package main
 
 type Request struct {
        a, b    int;
-       replyc  *chan int;
+       replyc  chan int;
 }
 
 type BinOp (a, b int) int;
@@ -16,7 +16,7 @@ func Run(op *BinOp, request *Request) {
        request.replyc <- result;
 }
 
-func Server(op *BinOp, service *chan *Request, quit *chan bool) {
+func Server(op *BinOp, service chan *Request, quit chan bool) {
        for {
                select {
                case request := <-service:
@@ -27,9 +27,9 @@ func Server(op *BinOp, service *chan *Request, quit *chan bool) {
        }
 }
 
-func StartServer(op *BinOp) (service *chan *Request, quit *chan bool) {
-       service = new(chan *Request);
-       quit = new(chan bool);
+func StartServer(op *BinOp) (service chan *Request, quit chan bool) {
+       service = make(chan *Request);
+       quit = make(chan bool);
        go Server(op, service, quit);
        return service, quit;
 }
@@ -42,7 +42,7 @@ func main() {
                req := &reqs[i];
                req.a = i;
                req.b = i + N;
-               req.replyc = new(chan int);
+               req.replyc = make(chan int);
                adder <- req;
        }
        for i := N-1; i >= 0; i-- {   // doesn't matter what order
index 1ee60bddfaf3de31199a2e0c02c15027130d1153..22e14535e30107df626ef93bc198333a9c04c61b 100644 (file)
@@ -5,7 +5,7 @@
 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'.
        }
@@ -13,9 +13,9 @@ func Generate(ch *chan int) {
 
 // Copy the values from channel 'in' to channel 'out',
 // removing those divisible by 'prime'.
-func Filter(in, out *chan int, prime int) {
+func Filter(in, out chan int, prime int) {
        for {
-               i := <-in  // Receive value of new variable 'i' from 'in'.
+               i := <-in;  // Receive value of new variable 'i' from 'in'.
                if i % prime != 0 {
                        out <- i  // Send 'i' to channel 'out'.
                }
@@ -24,12 +24,12 @@ func Filter(in, out *chan int, prime int) {
 
 // The prime sieve: Daisy-chain Filter processes together.
 func main() {
-       ch := new(chan int);  // Create a new channel.
+       ch := make(chan int);  // Create a new channel.
        go Generate(ch);  // Start Generate() as a goroutine.
        for {
                prime := <-ch;
                print(prime, "\n");
-               ch1 := new(chan int);
+               ch1 := make(chan int);
                go Filter(ch, ch1, prime);
                ch = ch1
        }
index d1c3c7277dfbe63cbed544f929fccc87d0860569..3f2cb9eac3a84661f0c168ab41c4d8037f55435a 100644 (file)
@@ -5,9 +5,9 @@
 package main
 
 // Send the sequence 2, 3, 4, ... to returned channel 
-func Generate() *chan int {
-       ch := new(chan int);
-       go func(ch *chan int){
+func Generate() chan int {
+       ch := make(chan int);
+       go func(ch chan int){
                for i := 2; ; i++ {
                        ch <- i
                }
@@ -16,9 +16,9 @@ func Generate() *chan int {
 }
 
 // Filter out input values divisible by 'prime', send rest to returned channel
-func Filter(in *chan int, prime int) *chan int {
-       out := new(chan int);
-       go func(in *chan int, out *chan int, prime int) {
+func Filter(in chan int, prime int) chan int {
+       out := make(chan int);
+       go func(in chan int, out chan int, prime int) {
                for {
                        if i := <-in; i % prime != 0 {
                                out <- i
@@ -28,9 +28,9 @@ func Filter(in *chan int, prime int) *chan int {
        return out;
 }
 
-func Sieve() *chan int {
-       out := new(chan int);
-       go func(out *chan int) {
+func Sieve() chan int {
+       out := make(chan int);
+       go func(out chan int) {
                ch := Generate();
                for {
                        prime := <-ch;
index bba8c229b93de2ffc8de1ea906f41c02d853546a..1e9f156c323fab8daf6e9fb3d2d8e290d354c4fc 100755 (executable)
@@ -58,6 +58,10 @@ make smoketest
 # # make test
 # ) || exit $?
 
+(xcd ../doc/progs
+time run
+) || exit $?
+
 (xcd ../test
 ./run
 ) || exit $?