func main() {
if sys.argc() != 3 {
- panic "argc"
+ panic("argc")
}
if sys.argv(1) != "arg1" {
- panic "arg1"
+ panic("arg1")
}
if sys.argv(2) != "arg2" {
- panic "arg2"
+ panic("arg2")
}
}
i3 := new(I); i3.val = 3333;
i4 := new(I); i4.val = 44444;
v := New();
- print "hi\n";
+ print("hi\n");
v.Insert(i4);
v.Insert(i3);
v.Insert(i2);
for i := 0; i < v.nelem; i++ {
var x *I;
x = v.At(i);
- print i, " ", x.val, "\n"; // prints correct list
+ print(i, " ", x.val, "\n"); // prints correct list
}
for i := 0; i < v.nelem; i++ {
- print i, " ", I(v.At(i)).val, "\n"; // always prints 5 - bad code - should be *I()
+ print(i, " ", I(v.At(i)).val, "\n"); // always prints 5 - bad code - should be *I()
}
}
/*
s.name = "foo";
s.fields = v;
if s.field(0).name != "hi" {
- panic "bad name"
+ panic("bad name")
}
}
m[0] = 0;
m[0]++;
if m[0] != 1 {
- print "map does not increment";
+ print("map does not increment");
sys.exit(1)
}
}
b := 2;
a, b = swap(swap(a, b));
if a != 2 || b != 1 {
- panic "bad swap";
+ panic("bad swap");
}
}
var i, j, k int;
outer:
for k=0; k<2; k++ {
- print "outer loop top k ", k, "\n";
- if k != 0 { panic "k not zero" } // inner loop breaks this one every time
+ print("outer loop top k ", k, "\n");
+ if k != 0 { panic("k not zero") } // inner loop breaks this one every time
for i=0; i<2; i++ {
- if i != 0 { panic "i not zero" } // loop breaks every time
- print "inner loop top i ", i, "\n";
+ if i != 0 { panic("i not zero") } // loop breaks every time
+ print("inner loop top i ", i, "\n");
if true {
- print "do break\n";
+ print("do break\n");
break outer;
}
}
}
- print "broke\n";
+ print("broke\n");
}
func main() {
x := string('a', 'b', '\n');
- print x;
+ print(x);
}
var x int
func foo() {
- print P.x; // P should be defined between the outermost "universe" scope and the global scope
+ print(P.x); // P should be defined between the outermost "universe" scope and the global scope
}
/*
}
func main() {
- print f(), "\n";
+ print(f(), "\n");
}
/*
}
for i := 0; i < N; i++ {
if <-ch != i {
- print "bad receive\n";
+ print("bad receive\n");
sys.exit(1);
}
}
func Chain(ch *chan<- int, val int, in *chan<- int, out *chan-< int) {
<-in;
if <-ch != val {
- panic val
+ panic(val)
}
out -< 1
}
}
func i32receiver(c *chan int32) {
- if <-c != 123 { panic "i32 value" }
+ if <-c != 123 { panic("i32 value") }
}
func i32sender(c *chan int32) {
}
func i64receiver(c *chan int64) {
- if <-c != 123456 { panic "i64 value" }
+ if <-c != 123456 { panic("i64 value") }
}
func i64sender(c *chan int64) {
}
func breceiver(c *chan bool) {
- if ! <-c { panic "b value" }
+ if ! <-c { panic("b value") }
}
func bsender(c *chan bool) {
}
func sreceiver(c *chan string) {
- if <-c != "hello" { panic "s value" }
+ if <-c != "hello" { panic("s value") }
}
func ssender(c *chan string) {
cs := new(chan string);
i32, ok = <-c32;
- if ok { panic "blocked i32sender" }
+ if ok { panic("blocked i32sender") }
i64, ok = <-c64;
- if ok { panic "blocked i64sender" }
+ if ok { panic("blocked i64sender") }
b, ok = <-cb;
- if ok { panic "blocked bsender" }
+ if ok { panic("blocked bsender") }
s, ok = <-cs;
- if ok { panic "blocked ssender" }
+ if ok { panic("blocked ssender") }
go i32receiver(c32);
pause();
ok = c32 -< 123;
- if !ok { panic "i32receiver" }
+ if !ok { panic("i32receiver") }
go i32sender(c32);
pause();
i32, ok = <-c32;
- if !ok { panic "i32sender" }
- if i32 != 234 { panic "i32sender value" }
+ if !ok { panic("i32sender") }
+ if i32 != 234 { panic("i32sender value") }
go i64receiver(c64);
pause();
ok = c64 -< 123456;
- if !ok { panic "i64receiver" }
+ if !ok { panic("i64receiver") }
go i64sender(c64);
pause();
i64, ok = <-c64;
- if !ok { panic "i64sender" }
- if i64 != 234567 { panic "i64sender value" }
+ if !ok { panic("i64sender") }
+ if i64 != 234567 { panic("i64sender value") }
go breceiver(cb);
pause();
ok = cb -< true;
- if !ok { panic "breceiver" }
+ if !ok { panic("breceiver") }
go bsender(cb);
pause();
b, ok = <-cb;
- if !ok { panic "bsender" }
- if !b{ panic "bsender value" }
+ if !ok { panic("bsender") }
+ if !b{ panic("bsender value") }
go sreceiver(cs);
pause();
ok = cs -< "hello";
- if !ok { panic "sreceiver" }
+ if !ok { panic("sreceiver") }
go ssender(cs);
pause();
s, ok = <-cs;
- if !ok { panic "ssender" }
- if s != "hello again" { panic "ssender value" }
- print "PASS\n"
+ if !ok { panic("ssender") }
+ if s != "hello again" { panic("ssender value") }
+ print("PASS\n")
}
}
func (u *rat) pr(){
- if u.den==1 { print u.num }
- else { print u.num, "/", u.den }
+ if u.den==1 { print(u.num) }
+ else { print(u.num, "/", u.den) }
print(" ")
}
func getn(in *[]*dch, n int) *[]item {
// BUG n:=len(in);
- if n != 2 { panic "bad n in getn" };
+ if n != 2 { panic("bad n in getn") };
req := new([2] *chan int);
dat := new([2] *chan item);
out := new([2] item);
}
func inv(u *rat) *rat{ // invert a rat
- if u.num == 0 { panic "zero divide in inv" }
+ if u.num == 0 { panic("zero divide in inv") }
return i2tor(u.den, u.num);
}
val = val + x * float64(u.num)/float64(u.den);
xn = xn*x;
}
- print val, "\n";
+ print(val, "\n");
}
// Print n terms of a power series
if end(u) != 0 { done = true }
else { u.pr() }
}
- print ("\n");
+ print(("\n"));
}
func Print(U PS){
for i := 0; i < count; i++ {
r := get(U)
if !r.eq(c) {
- print "got: ";
+ print("got: ");
r.pr();
- print "should get ";
+ print("should get ");
c.pr();
- print "\n";
- panic str
+ print("\n");
+ panic(str)
}
}
}
func main() {
Init();
if sys.argc() > 1 { // print
- print "Ones: "; Printn(Ones, 10);
- print "Twos: "; Printn(Twos, 10);
- print "Add: "; Printn(Add(Ones, Twos), 10);
- print "Diff: "; Printn(Diff(Ones), 10);
- print "Integ: "; Printn(Integ(zero, Ones), 10);
- print "CMul: "; Printn(Cmul(neg(one), Ones), 10);
- print "Sub: "; Printn(Sub(Ones, Twos), 10);
- print "Mul: "; Printn(Mul(Ones, Ones), 10);
- print "Exp: "; Printn(Exp(Ones), 15);
- print "MonSubst: "; Printn(MonSubst(Ones, neg(one), 2), 10);
- print "ATan: "; Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10);
+ print("Ones: "); Printn(Ones, 10);
+ print("Twos: "); Printn(Twos, 10);
+ print("Add: "); Printn(Add(Ones, Twos), 10);
+ print("Diff: "); Printn(Diff(Ones), 10);
+ print("Integ: "); Printn(Integ(zero, Ones), 10);
+ print("CMul: "); Printn(Cmul(neg(one), Ones), 10);
+ print("Sub: "); Printn(Sub(Ones, Twos), 10);
+ print("Mul: "); Printn(Mul(Ones, Ones), 10);
+ print("Exp: "); Printn(Exp(Ones), 15);
+ print("MonSubst: "); Printn(MonSubst(Ones, neg(one), 2), 10);
+ print("ATan: "); Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10);
} else { // test
check(Ones, one, 5, "Ones");
check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1
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 }
+ 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) }
sys.exit(0);
}
'\Ucafebabe'
;
if '\Ucafebabe' != 0xcafebabe {
- print "cafebabe wrong\n";
+ print("cafebabe wrong\n");
sys.exit(1)
}
if i != 0xcc238de1 {
- print "number is ", i, " should be ", 0xcc238de1, "\n";
+ print("number is ", i, " should be ", 0xcc238de1, "\n");
sys.exit(1)
}
}
);
func main() {
- if g == 0.0 { print "zero\n";}
- if g != 4.5 { print " fail\n"; sys.exit(1); }
+ if g == 0.0 { print("zero\n");}
+ if g != 4.5 { print(" fail\n"); sys.exit(1); }
}
var u31 uint64 = 1;
var u32 uint64 = 18446744073709551615;
var u33 uint64 = +18446744073709551615;
- if u32 != (1<<64)-1 { panic "u32\n"; }
- if u33 != (1<<64)-1 { panic "u33\n"; }
+ if u32 != (1<<64)-1 { panic("u32\n"); }
+ if u33 != (1<<64)-1 { panic("u33\n"); }
var i34 int64 = ^0; // note: 2's complement means ^0 == -1
- if i34 != -1 { panic "i34" }
+ if i34 != -1 { panic("i34") }
}
/*
bug12.go:5: overflow converting constant to <uint64>UINT64
func main() {
s := Alloc(7);
- if s != 5 { panic "bad" }
+ if s != 5 { panic("bad") }
}
/*
package main
func main() {
- go func() { print "ok\n" } ();
+ go func() { print("ok\n") } ();
}
func main() {
x := 0;
x = ^x; // unary ^ not yet implemented
- if x != ^0 { panic x, " ", ^0 }
+ if x != ^0 { panic(x, " ", ^0) }
}
/*
}
func (s *Service) Serve(a int64) {
- if a != 1234 { panic a, " not 1234\n" }
+ if a != 1234 { panic(a, " not 1234\n") }
}
var arith Service
main()
{
- if !close(0., 0, 1, 0) { print "0. is ", 0., "\n"; }
- if !close(+10., 10, 1, 0) { print "+10. is ", +10., "\n"; }
- if !close(-210., -210, 1, 0) { print "-210. is ", -210., "\n"; }
+ if !close(0., 0, 1, 0) { print("0. is ", 0., "\n"); }
+ if !close(+10., 10, 1, 0) { print("+10. is ", +10., "\n"); }
+ if !close(-210., -210, 1, 0) { print("-210. is ", -210., "\n"); }
- if !close(.0, 0, 1, 0) { print ".0 is ", .0, "\n"; }
- if !close(+.01, 1, 100, 0) { print "+.01 is ", +.01, "\n"; }
- if !close(-.012, -12, 1000, 0) { print "-.012 is ", -.012, "\n"; }
+ if !close(.0, 0, 1, 0) { print(".0 is ", .0, "\n"); }
+ if !close(+.01, 1, 100, 0) { print("+.01 is ", +.01, "\n"); }
+ if !close(-.012, -12, 1000, 0) { print("-.012 is ", -.012, "\n"); }
- if !close(0.0, 0, 1, 0) { print "0.0 is ", 0.0, "\n"; }
- if !close(+10.01, 1001, 100, 0) { print "+10.01 is ", +10.01, "\n"; }
- if !close(-210.012, -210012, 1000, 0) { print "-210.012 is ", -210.012, "\n"; }
+ if !close(0.0, 0, 1, 0) { print("0.0 is ", 0.0, "\n"); }
+ if !close(+10.01, 1001, 100, 0) { print("+10.01 is ", +10.01, "\n"); }
+ if !close(-210.012, -210012, 1000, 0) { print("-210.012 is ", -210.012, "\n"); }
- if !close(0E+1, 0, 1, 0) { print "0E+1 is ", 0E+1, "\n"; }
- if !close(+10e2, 10, 1, 2) { print "+10e2 is ", +10e2, "\n"; }
- if !close(-210e3, -210, 1, 3) { print "-210e3 is ", -210e3, "\n"; }
+ if !close(0E+1, 0, 1, 0) { print("0E+1 is ", 0E+1, "\n"); }
+ if !close(+10e2, 10, 1, 2) { print("+10e2 is ", +10e2, "\n"); }
+ if !close(-210e3, -210, 1, 3) { print("-210e3 is ", -210e3, "\n"); }
- if !close(0E-1, 0, 1, 0) { print "0E-1 is ", 0E-1, "\n"; }
- if !close(+0e23, 0, 1, 23) { print "+0e23 is ", +0e23, "\n"; }
- if !close(-0e345, 0, 1, 345) { print "-0e345 is ", -0e345, "\n"; }
+ if !close(0E-1, 0, 1, 0) { print("0E-1 is ", 0E-1, "\n"); }
+ if !close(+0e23, 0, 1, 23) { print("+0e23 is ", +0e23, "\n"); }
+ if !close(-0e345, 0, 1, 345) { print("-0e345 is ", -0e345, "\n"); }
- if !close(0E1, 0, 1, 1) { print "0E1 is ", 0E1, "\n"; }
- if !close(+10e23, 10, 1, 23) { print "+10e23 is ", +10e23, "\n"; }
- if !close(-210e34, -210, 1, 34) { print "-210e34 is ", -210e34, "\n"; }
+ if !close(0E1, 0, 1, 1) { print("0E1 is ", 0E1, "\n"); }
+ if !close(+10e23, 10, 1, 23) { print("+10e23 is ", +10e23, "\n"); }
+ if !close(-210e34, -210, 1, 34) { print("-210e34 is ", -210e34, "\n"); }
- if !close(0.E1, 0, 1, 1) { print "0.E1 is ", 0.E1, "\n"; }
- if !close(+10.e+2, 10, 1, 2) { print "+10.e+2 is ", +10.e+2, "\n"; }
- if !close(-210.e-3, -210, 1, -3) { print "-210.e-3 is ", -210.e-3, "\n"; }
+ if !close(0.E1, 0, 1, 1) { print("0.E1 is ", 0.E1, "\n"); }
+ if !close(+10.e+2, 10, 1, 2) { print("+10.e+2 is ", +10.e+2, "\n"); }
+ if !close(-210.e-3, -210, 1, -3) { print("-210.e-3 is ", -210.e-3, "\n"); }
- if !close(.0E1, 0, 1, 1) { print ".0E1 is ", .0E1, "\n"; }
- if !close(+.01e2, 1, 100, 2) { print "+.01e2 is ", +.01e2, "\n"; }
- if !close(-.012e3, -12, 1000, 3) { print "-.012e3 is ", -.012e3, "\n"; }
+ if !close(.0E1, 0, 1, 1) { print(".0E1 is ", .0E1, "\n"); }
+ if !close(+.01e2, 1, 100, 2) { print("+.01e2 is ", +.01e2, "\n"); }
+ if !close(-.012e3, -12, 1000, 3) { print("-.012e3 is ", -.012e3, "\n"); }
- if !close(0.0E1, 0, 1, 0) { print "0.0E1 is ", 0.0E1, "\n"; }
- if !close(+10.01e2, 1001, 100, 2) { print "+10.01e2 is ", +10.01e2, "\n"; }
- if !close(-210.012e3, -210012, 1000, 3) { print "-210.012e3 is ", -210.012e3, "\n"; }
+ if !close(0.0E1, 0, 1, 0) { print("0.0E1 is ", 0.0E1, "\n"); }
+ if !close(+10.01e2, 1001, 100, 2) { print("+10.01e2 is ", +10.01e2, "\n"); }
+ if !close(-210.012e3, -210012, 1000, 3) { print("-210.012e3 is ", -210.012e3, "\n"); }
- if !close(0.E+12, 0, 1, 0) { print "0.E+12 is ", 0.E+12, "\n"; }
- if !close(+10.e23, 10, 1, 23) { print "+10.e23 is ", +10.e23, "\n"; }
- if !close(-210.e33, -210, 1, 33) { print "-210.e33 is ", -210.e33, "\n"; }
+ if !close(0.E+12, 0, 1, 0) { print("0.E+12 is ", 0.E+12, "\n"); }
+ if !close(+10.e23, 10, 1, 23) { print("+10.e23 is ", +10.e23, "\n"); }
+ if !close(-210.e33, -210, 1, 33) { print("-210.e33 is ", -210.e33, "\n"); }
- if !close(.0E-12, 0, 1, 0) { print ".0E-12 is ", .0E-12, "\n"; }
- if !close(+.01e23, 1, 100, 23) { print "+.01e23 is ", +.01e23, "\n"; }
- if !close(-.012e34, -12, 1000, 34) { print "-.012e34 is ", -.012e34, "\n"; }
+ if !close(.0E-12, 0, 1, 0) { print(".0E-12 is ", .0E-12, "\n"); }
+ if !close(+.01e23, 1, 100, 23) { print("+.01e23 is ", +.01e23, "\n"); }
+ if !close(-.012e34, -12, 1000, 34) { print("-.012e34 is ", -.012e34, "\n"); }
- if !close(0.0E12, 0, 1, 12) { print "0.0E12 is ", 0.0E12, "\n"; }
- if !close(+10.01e23, 1001, 100, 23) { print "+10.01e23 is ", +10.01e23, "\n"; }
- if !close(-210.012e33, -210012, 1000, 33) { print "-210.012e33 is ", -210.012e33, "\n"; }
+ if !close(0.0E12, 0, 1, 12) { print("0.0E12 is ", 0.0E12, "\n"); }
+ if !close(+10.01e23, 1001, 100, 23) { print("+10.01e23 is ", +10.01e23, "\n"); }
+ if !close(-210.012e33, -210012, 1000, 33) { print("-210.012e33 is ", -210.012e33, "\n"); }
- if !close(0.E123, 0, 1, 123) { print "0.E123 is ", 0.E123, "\n"; }
- if !close(+10.e+23, 10, 1, 23) { print "+10.e+234 is ", +10.e+234, "\n"; }
- if !close(-210.e-35, -210, 1, -35) { print "-210.e-35 is ", -210.e-35, "\n"; }
+ if !close(0.E123, 0, 1, 123) { print("0.E123 is ", 0.E123, "\n"); }
+ if !close(+10.e+23, 10, 1, 23) { print("+10.e+234 is ", +10.e+234, "\n"); }
+ if !close(-210.e-35, -210, 1, -35) { print("-210.e-35 is ", -210.e-35, "\n"); }
- if !close(.0E123, 0, 1, 123) { print ".0E123 is ", .0E123, "\n"; }
- if !close(+.01e29, 1, 100, 29) { print "+.01e29 is ", +.01e29, "\n"; }
- if !close(-.012e29, -12, 1000, 29) { print "-.012e29 is ", -.012e29, "\n"; }
+ if !close(.0E123, 0, 1, 123) { print(".0E123 is ", .0E123, "\n"); }
+ if !close(+.01e29, 1, 100, 29) { print("+.01e29 is ", +.01e29, "\n"); }
+ if !close(-.012e29, -12, 1000, 29) { print("-.012e29 is ", -.012e29, "\n"); }
- if !close(0.0E123, 0, 1, 123) { print "0.0E123 is ", 0.0E123, "\n"; }
- if !close(+10.01e31, 1001, 100, 31) { print "+10.01e31 is ", +10.01e31, "\n"; }
- if !close(-210.012e19, -210012, 1000, 19) { print "-210.012e19 is ", -210.012e19, "\n"; }
+ if !close(0.0E123, 0, 1, 123) { print("0.0E123 is ", 0.0E123, "\n"); }
+ if !close(+10.01e31, 1001, 100, 31) { print("+10.01e31 is ", +10.01e31, "\n"); }
+ if !close(-210.012e19, -210012, 1000, 19) { print("-210.012e19 is ", -210.012e19, "\n"); }
}
func E(f *fmt.Fmt, e string) {
g := f.str();
if sys.argc() > 1 {
- print g, "\n";
+ print(g, "\n");
if g != e {
- print "expected <", e, ">\n";
+ print("expected <", e, ">\n");
}
return;
}
if g != e {
- print "expected <", e, ">\n";
- print "got <", g, ">\n"
+ print("expected <", e, ">\n");
+ print("got <", g, ">\n");
}
}
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail", msg, "\n";
- panic 1;
+ print("assertion fail", msg, "\n");
+ panic(1);
}
}
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail", msg, "\n";
- panic 1;
+ print("assertion fail", msg, "\n");
+ panic(1);
}
}
(MAP[<int32>INT32]<int32>INT32)
BUG: known to fail incorrectly
-=========== bugs/bug053.go
-bugs/bug053.go:6: syntax error
-BUG: len should not be a keyword
-
=========== bugs/bug054.go
bugs/bug054.go:25: fatal error: agen_inter i2s
BUG: known to fail incorrectly
package main
func main() {
- print "hello, world\n";
+ print("hello, world\n");
}
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail", msg, "\n";
- panic 1;
+ print("assertion fail", msg, "\n");
+ panic(1);
}
}
count = count + one
}
if count != 8 {
- print count, " should be 8\n";
+ print(count, " should be 8\n");
sys.exit(1)
}
}
0X0 +
0X123;
if s != 788 {
- print "s is ", s, "; should be 788\n";
+ print("s is ", s, "; should be 788\n");
sys.exit(1);
}
}
func assert(cond bool, msg string) {
if !cond {
- print "assertion fail: ", msg, "\n";
- panic 1;
+ print("assertion fail: ", msg, "\n");
+ panic(1);
}
}
for i=0; i<100; i=i+1 {
t = t+i;
}
- if t != 50*99 { panic t; }
+ if t != 50*99 { panic(t); }
}
s.b = 6;
// call structure
- if s.f() != 5 { panic 11; }
- if s.g() != 6 { panic 12; }
+ if s.f() != 5 { panic(11); }
+ if s.g() != 6 { panic(12); }
i1 = s; // convert S to I1
i2 = i1; // convert I1 to I2
// call interface
- if i1.f() != 5 { panic 21; }
- if i2.f() != 5 { panic 22; }
- if i2.g() != 6 { panic 23; }
+ if i1.f() != 5 { panic(21); }
+ if i2.f() != 5 { panic(22); }
+ if i2.g() != 6 { panic(23); }
g = i1; // convert I1 to S
- if g != s { panic 31; }
+ if g != s { panic(31); }
g = i2; // convert I2 to S
- if g != s { panic 32; }
+ if g != s { panic(32); }
}
func (p *Print)
dop()
{
- print " print ", p.whoami;
+ print(" print ", p.whoami);
p.put.puts("abc");
}
func (b *Bio)
puts(s string)
{
- print " bio ", b.whoami;
+ print(" bio ", b.whoami);
b.put.puts(s);
}
func (f *File)
puts(s string)
{
- print " file ", f.whoami, " -- ", s;
+ print(" file ", f.whoami, " -- ", s);
}
func
f.whoami = 3;
p.dop();
- print "\n";
+ print("\n");
}
if i < 100 {
goto loop;
}
- print i;
- print "\n";
+ print(i);
+ print("\n");
return;
gogoloop:
};
return x(a)+11;
};
- if x(3) != 3+5+7+11 { panic x(3); }
+ if x(3) != 3+5+7+11 { panic(x(3)); }
}
var x,y int;
x,y = simple(10,20,30);
- if x+y != 65 { panic x+y; }
+ if x+y != 65 { panic(x+y); }
}
func
c.x = &g;
v = g(c);
- if v != 6 { panic v; }
+ if v != 6 { panic(v); }
v = c.x(c);
- if v != 6 { panic v; }
+ if v != 6 { panic(v); }
v = c.f();
- if v != 6 { panic v; }
+ if v != 6 { panic(v); }
}
func
var v int;
v = p.a;
- if v != 6 { panic v; }
+ if v != 6 { panic(v); }
return p.a;
}
s2.d.c = 23;
s2.d.d = 20;
- if(s2.d.c != 23) { panic 1; }
- if(g2.d.c != 23) { panic 2; }
+ if(s2.d.c != 23) { panic(1); }
+ if(g2.d.c != 23) { panic(2); }
x = s1.a +
s1.b +
s2.d.c +
s2.d.d;
- if(x != 121) { panic x; }
+ if(x != 121) { panic(x); }
}
func (this *Integer)
Print()
{
- print this.val;
+ print(this.val);
}
func
}
list.Print();
- print "\n";
+ print("\n");
}
}
if slist.isatom {
if slist.isstring {
- print slist.String();
+ print(slist.String());
} else {
- print slist.Integer();
+ print(slist.Integer());
}
} else {
if doparen {
- print "(" ;
+ print("(" );
}
slist.Car().PrintOne(true);
if slist.Cdr() != nil {
- print " ";
+ print(" ");
slist.Cdr().PrintOne(false);
}
if doparen {
- print ")";
+ print(")");
}
}
}
func (slist *Slist) Print()
{
slist.PrintOne(true);
- print "\n";
+ print("\n");
}
func Get() int
}
}
if i >= 100 - 1 { // sizeof tokenbuf - 1
- panic "atom too long\n";
+ panic("atom too long\n");
}
tokenlen = i;
tokenbuf[i] = nilchar;
func Expect(c int)
{
if token != c {
- print "parse error: expected ", c, "\n";
- panic "parse";
+ print("parse error: expected ", c, "\n");
+ panic("parse");
}
NextToken();
}
slist = atom(0);
default:
slist = nil;
- print "unknown token"; //, token, tokenbuf;
+ print("unknown token"); // token, tokenbuf);
}
NextToken();
return slist;
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail" + msg + "\n";
- panic 1;
+ print("assertion fail" + msg + "\n");
+ panic(1);
}
}
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail" + msg + "\n";
- panic 1;
+ print("assertion fail" + msg + "\n");
+ panic(1);
}
}
func assertequal(is, shouldbe int, msg string) {
if is != shouldbe {
- print "assertion fail" + msg + "\n";
- panic 1;
+ print("assertion fail" + msg + "\n");
+ panic(1);
}
}
func assert(cond bool, msg string) {
if !cond {
- print "assertion fail: " + msg + "\n";
- panic 1;
+ print("assertion fail: " + msg + "\n");
+ panic(1);
}
}
s1 = s1 + a[i];
}
- if s1 != 35 { panic s1; }
+ if s1 != 35 { panic(s1); }
for i:=short(5); i<10; i=i+1 {
b[i] = float(i);
s2 = s2 + b[i];
}
- if s2 != 35 { panic s2; }
+ if s2 != 35 { panic(s2); }
b := new([100]int);
for i:=0; i<100; i=i+1 {
s3 = s3+b[i];
}
- if s3 != 4950 { panic s3; }
+ if s3 != 4950 { panic(s3); }
}
a = true;
b = false;
- if !a { panic 1; }
- if b { panic 2; }
- if !!!a { panic 3; }
- if !!b { panic 4; }
+ if !a { panic(1); }
+ if b { panic(2); }
+ if !!!a { panic(3); }
+ if !!b { panic(4); }
a = !b;
- if !a { panic 5; }
- if !!!a { panic 6; }
+ if !a { panic(5); }
+ if !!!a { panic(6); }
var x *s;
x = new(s);
x.a = true;
x.b = false;
- if !x.a { panic 7; }
- if x.b { panic 8; }
- if !!!x.a { panic 9; }
- if !!x.b { panic 10; }
+ if !x.a { panic(7); }
+ if x.b { panic(8); }
+ if !!!x.a { panic(9); }
+ if !!x.b { panic(10); }
x.a = !x.b;
- if !x.a { panic 11; }
- if !!!x.a { panic 12; }
+ if !x.a { panic(11); }
+ if !!!x.a { panic(12); }
/*
* test &&
*/
a = true;
b = true;
- if !(a && b) { panic 21; }
- if a && !b { panic 22; }
- if !a && b { panic 23; }
- if !a && !b { panic 24; }
+ if !(a && b) { panic(21); }
+ if a && !b { panic(22); }
+ if !a && b { panic(23); }
+ if !a && !b { panic(24); }
a = false;
b = true;
- if !(!a && b) { panic 31; }
- if !a && !b { panic 32; }
- if a && b { panic 33; }
- if a && !b { panic 34; }
+ if !(!a && b) { panic(31); }
+ if !a && !b { panic(32); }
+ if a && b { panic(33); }
+ if a && !b { panic(34); }
a = true;
b = false;
- if !(a && !b) { panic 41; }
- if a && b { panic 41; }
- if !a && !b { panic 41; }
- if !a && b { panic 44; }
+ if !(a && !b) { panic(41); }
+ if a && b { panic(41); }
+ if !a && !b { panic(41); }
+ if !a && b { panic(44); }
a = false;
b = false;
- if !(!a && !b) { panic 51; }
- if !a && b { panic 52; }
- if a && !b { panic 53; }
- if a && b { panic 54; }
+ if !(!a && !b) { panic(51); }
+ if !a && b { panic(52); }
+ if a && !b { panic(53); }
+ if a && b { panic(54); }
/*
* test ||
*/
a = true;
b = true;
- if !(a || b) { panic 61; }
- if !(a || !b) { panic 62; }
- if !(!a || b) { panic 63; }
- if !a || !b { panic 64; }
+ if !(a || b) { panic(61); }
+ if !(a || !b) { panic(62); }
+ if !(!a || b) { panic(63); }
+ if !a || !b { panic(64); }
a = false;
b = true;
- if !(!a || b) { panic 71; }
- if !(!a || !b) { panic 72; }
- if !(a || b) { panic 73; }
- if a || !b { panic 74; }
+ if !(!a || b) { panic(71); }
+ if !(!a || !b) { panic(72); }
+ if !(a || b) { panic(73); }
+ if a || !b { panic(74); }
a = true;
b = false;
- if !(a || !b) { panic 81; }
- if !(a || b) { panic 82; }
- if !(!a || !b) { panic 83; }
- if !a || b { panic 84; }
+ if !(a || !b) { panic(81); }
+ if !(a || b) { panic(82); }
+ if !(!a || !b) { panic(83); }
+ if !a || b { panic(84); }
a = false;
b = false;
- if !(!a || !b) { panic 91; }
- if !(!a || b) { panic 92; }
- if !(a || !b) { panic 93; }
- if a || b { panic 94; }
+ if !(!a || !b) { panic(91); }
+ if !(!a || b) { panic(92); }
+ if !(a || !b) { panic(93); }
+ if a || b { panic(94); }
}
for i:=short(0); i<10; i=i+1 {
s1 = s1 + vlong(i);
}
- if s1 != 45 { panic s1; }
+ if s1 != 45 { panic(s1); }
s2 := float(0);
for i:=0; i<10; i=i+1 {
s2 = s2 + float(i);
}
- if s2 != 45 { panic s2; }
+ if s2 != 45 { panic(s2); }
}
var x int;
x = fun(10,20,30);
- if x != 60 { panic x; }
+ if x != 60 { panic(x); }
}
func
var o int;
o = ia+ib+ic;
- if o != 60 { panic o; }
+ if o != 60 { panic(o); }
return o;
}
func
main()
{
- print "hello world\n";
+ print("hello world\n");
}
for i:=0; i<10; i=i+1 {
switch(i) {
case 5:
- print "five";
+ print("five");
case a,7:
- print "a";
+ print("a");
default:
- print i;
+ print(i);
}
- print "out", i;
+ print("out", i);
}
- print "\n";
+ print("\n");
}
y = 25;
}
x = x+y;
- if(x != 40) { panic x; }
+ if(x != 40) { panic(x); }
}
b := `xyz`;
/* print a literal */
- print `abc`;
+ print(`abc`);
/* print a variable */
- print b, "-";
+ print(b, "-");
/* catenate literals */
- print `abc` + `xyz`, "-";
+ print(`abc` + `xyz`, "-");
/* catenate variables */
- print a+b, "-";
+ print(a+b, "-");
/* compare literals */
if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` {
- panic "compare literals";
+ panic("compare literals");
}
/* compare variables */
if a == b || a != a || a > b {
- panic "compare variables";
+ panic("compare variables");
}
/* cat */
c = a+b;
- print c, "-";
+ print(c, "-");
/* catequal */
c = a;
c += b;
- print c, "-";
+ print(c, "-");
/* clumsy evaluation */
c = b;
c = a + c;
- print c, "-";
+ print(c, "-");
/* len */
if len(c) != 6 {
- panic "len ", len(c);
+ panic("len ", len(c));
}
/* index strings */
for i:=0; i<len(c); i=i+1 {
if c[i] != (a+b)[i] {
- panic "index ", i, " ", c[i], " ", (a+b)[i];
+ panic("index ", i, " ", c[i], " ", (a+b)[i]);
}
}
/* slice strings */
- print c[0:3], c[3:6];
+ print(c[0:3], c[3:6]);
- print "\n";
+ print("\n");
/* create string with integer constant */
c = string('x');
if c != "x" {
- panic "create int ", c;
+ panic("create int ", c);
}
/* create string with integer variable */
v := 'x';
c = string(v);
if c != "x" {
- panic "create int ", c;
+ panic("create int ", c);
}
/* create string with byte array */
z1[2] = 'c';
c = string(z1);
if c != "abc" {
- panic "create array ", c;
+ panic("create array ", c);
}
/* create string with byte array pointer */
z2[2] = 'c';
c = string(z2);
if c != "abc" {
- panic "create array pointer ", c;
+ panic("create array pointer ", c);
}
}
s1.c = 3;
s1.d = 5;
- if(s1.c != 3) { panic s1.c; }
- if(g1.c != 3) { panic g1.c; }
+ if(s1.c != 3) { panic(s1.c); }
+ if(g1.c != 3) { panic(g1.c); }
s2.a = 7;
s2.b = 11;
s2.d.c = 23;
s2.d.d = 29;
- if(s2.d.c != 23) { panic s2.d.c; }
- if(g2.d.c != 23) { panic g2.d.c; }
+ if(s2.d.c != 23) { panic(s2.d.c); }
+ if(g2.d.c != 23) { panic(g2.d.c); }
x = s1.a +
s1.b +
s2.d.c +
s2.d.d;
- if(x != 130) { panic x; }
+ if(x != 130) { panic(x); }
// test an automatic struct
s3.a = 7;
s3.d.c = 23;
s3.d.d = 29;
- if(s3.d.c != 23) { panic s3.d.c; }
+ if(s3.d.c != 23) { panic(s3.d.c); }
x = s3.a +
s3.b +
s3.d.c +
s3.d.d;
- if(x != 119) { panic x; }
+ if(x != 119) { panic(x); }
}
func assert(cond bool, msg string) {
if !cond {
- print "assertion fail: ", msg, "\n";
- panic 1;
+ print("assertion fail: ", msg, "\n");
+ panic(1);
}
}
func check(x *Number, expected int) {
var c = count(x);
if c != expected {
- panic "error: found ", c, "; expected ", expected, "\n";
+ panic("error: found ", c, "; expected ", expected, "\n");
}
}
verify();
for i := 0; i <= 10; i++ {
- print i, "! = ", count(fact(gen(i))), "\n";
+ print(i, "! = ", count(fact(gen(i))), "\n");
}
}
s, ok = sys.readfile("readfile.go");
if !ok {
- print "couldn't readfile\n";
+ print("couldn't readfile\n");
sys.exit(1)
}
start_of_file :=
"\n" +
"package main\n";
if s[0:102] != start_of_file {
- print "wrong data\n";
+ print("wrong data\n");
sys.exit(1)
}
}
go Generate(ch); // Start Generate() as a subprocess.
for {
prime := <-ch;
- print prime, "\n";
+ print(prime, "\n");
ch1 := new(chan int);
go Filter(ch, ch1, prime);
ch = ch1
func
printit()
{
- print a,b,c,d,e,f,g,h,i,"\n";
+ print(a,b,c,d,e,f,g,h,i,"\n");
}
func
testit() bool
{
if a+b+c+d+e+f+g+h+i != 45 {
- print "sum does not add to 45\n";
+ print("sum does not add to 45\n");
printit();
- panic;
+ panic();
}
return a == 1 &&
b == 2 &&
h = 8;
i = 9;
- if !testit() { panic "init val\n"; }
+ if !testit() { panic("init val\n"); }
for z:=0; z<100; z++ {
a,b,c,d, e,f,g,h,i = b,c,d,a, i,e,f,g,h;
if z == 19 {
break;
}
- print "on ", z, "th iteration\n";
+ print("on ", z, "th iteration\n");
printit();
- panic;
+ panic();
}
}
if !testit() {
- print "final val\n";
+ print("final val\n");
printit();
- panic;
+ panic();
}
a, b = swap(1, 2);
if a != 2 || b != 1 {
- panic "bad swap";
+ panic("bad swap");
}
//BUG a, b = swap(swap(a, b));
// if a != 2 || b != 1 {
-// panic "bad swap";
+// panic("bad swap");
// }
}
func assert(a, b, c string) {
if a != b {
ecode = 1;
- print "FAIL: ", c, ": ", a, "!=", b, "\n";
+ print("FAIL: ", c, ": ", a, "!=", b, "\n");
var max int = len(a);
if len(b) > max {
max = len(b);
bc = int(b[i]);
}
if ac != bc {
- print "\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n";
+ print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n");
}
}
}
func assert(cond bool, msg string) {
if !cond {
- print "assertion fail: ", msg, "\n";
- panic 1;
+ print("assertion fail: ", msg, "\n");
+ panic(1);
}
}
case '-':
a[p]--;
case '.':
- print string(a[p]);
+ print(string(a[p]));
case '[':
if a[p] == 0 {
for nest := 1; nest > 0; pc++ {
for w, i, j := 0,0,0; i < l; i += w {
var r int32;
r, w = sys.stringtorune(s, i, l);
- if w == 0 { panic "zero width in string" }
- if r != chars[j] { panic "wrong value from string" }
+ if w == 0 { panic("zero width in string") }
+ if r != chars[j] { panic("wrong value from string") }
j++;
}
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
const L = 12;
- if L != l { panic "wrong length constructing array" }
+ if L != l { panic("wrong length constructing array") }
a := new([L]byte);
a[0] = 'a';
a[1] = 'b';
for w, i, j := 0,0,0; i < L; i += w {
var r int32;
r, w = sys.bytestorune(&a[0], i, L);
- if w == 0 { panic "zero width in bytes" }
- if r != chars[j] { panic "wrong value from bytes" }
+ if w == 0 { panic("zero width in bytes") }
+ if r != chars[j] { panic("wrong value from bytes") }
j++;
}
}