record array(a,b,c,d,e,f,g)

procedure p1()
   write(" ----> ",image() | "none")
   write("list(0) ----> ",image(list(0)) | "none")
   write("list(0,1) ----> ",image(list(0,1)) | "none")
   write("list(1,1) ----> ",image(list(1,1)) | "none")
   write("list(100,\"a\") ----> ",image(list(100,"a")) | "none")
   write("table() ----> ",image(table()) | "none")
   write("table(0) ----> ",image(table(0)) | "none")
   write("a := [] ----> ",image(a := []) | "none")
   write("every put(a,!&lcase) ----> ",image(every put(a,!&lcase)) | "none")
   write("a1 := sort(a) ----> ",image(a1 := sort(a)) | "none")
   write("every write(!a1) ----> ",image(every write(!a1)) | "none")
end

procedure p2()
   write("sort(a1) ----> ",image(sort(a1)) | "none")
   write("t := table() ----> ",image(t := table()) | "none")
   write("every t[!&lcase] := 1 ----> ",image(every t[!&lcase] := 1) | "none")
   write("sort(t) ----> ",image(sort(t)) | "none")
   write("a := sort(t) ----> ",image(a := sort(t)) | "none")
   write("every write((!a)[1]) ----> ",image(every write((!a)[1])) | "none")
   write("every write((!a)[2]) ----> ",image(every write((!a)[2])) | "none")
   write("set([1,0,1,0,1,0,1,0]) ----> ",image(set([1,0,1,0,1,0,1,0])) | "none")
   write("set([]) ----> ",image(set([])) | "none")
   write("s := set([1,2,3,4,5,6,7,8,9,10]) ----> ",image(s := set([1,2,3,4,5,6,7,8,9,10])) | "none")
   write("*s ----> ",image(*s) | "none")
end

procedure p3()
   write("every write(!sort(s)) ----> ",image(every write(!sort(s))) | "none")
   write("*copy(s) ----> ",image(*copy(s)) | "none")
   write("image(s) ----> ",image(image(s)) | "none")
   write("type(s) ----> ",image(type(s)) | "none")
   write("member(s,8) ----> ",image(member(s,8)) | "none")
   write("member(s,\"8\") ----> ",image(member(s,"8")) | "none")
   write("s := set([]) ----> ",image(s := set([])) | "none")
   write("every insert(s,1 to 100) ----> ",image(every insert(s,1 to 100)) | "none")
   write("*s ----> ",image(*s) | "none")
   write("every delete(s,15 to 30) ----> ",image(every delete(s,15 to 30)) | "none")
   write("*s ----> ",image(*s) | "none")
end

procedure p4()
   write("every s1 := insert(set([]),!&lcase) ----> ",image(every s1 := insert(set([]),!&lcase)) | "none")
   write("s2 := set([\"a\",\"aa\",\"ab\",\"b\",1,2,3,4]) ----> ",image(s2 := set(["a","aa","ab","b",1,2,3,4])) | "none")
   write("s3 := s1 ++ s2 ----> ",image(s3 := s1 ++ s2) | "none")
   write("s4 := s1 ** s2 ----> ",image(s4 := s1 ** s2) | "none")
   write("s5 := s1 -- s2 ----> ",image(s5 := s1 -- s2) | "none")
   write("*s3 ----> ",image(*s3) | "none")
   write("*s4 ----> ",image(*s4) | "none")
   write("*s5 ----> ",image(*s5) | "none")
   write("t := table() ----> ",image(t := table()) | "none")
   write("every t[1 | &output | &cset | [] | \"hello\" | main | 2 | table()] := ?100 ----> ",image(every t[1 | &output | &cset | [] | "hello" | main | 2 | table()] := ?100) | "none")
   write("a := sort(t,3) ----> ",image(a := sort(t,3)) | "none")
end

procedure p5()
   write("every i := 1 to *a - 1 by 2 do write(image(a[i]),\" \",a[i + 1]) ----> ",image(every i := 1 to *a - 1 by 2 do write(image(a[i])," ",a[i + 1])) | "none")
   write("a := sort(t,4) ----> ",image(a := sort(t,4)) | "none")
   write("every i := 1 to *a - 1 by 2 do write(image(a[i]),\" \",a[i + 1]) ----> ",image(every i := 1 to *a - 1 by 2 do write(image(a[i])," ",a[i + 1])) | "none")
   write("t := table() ----> ",image(t := table()) | "none")
   write("every t[1 | &output | &cset | [] | \"hello\" | main | 2 | table()] := ?100 ----> ",image(every t[1 | &output | &cset | [] | "hello" | main | 2 | table()] := ?100) | "none")
   write("a := sort(t,3) ----> ",image(a := sort(t,3)) | "none")
   write("every i := 1 to *a - 1 by 2 do write(image(a[i]),\" \",a[i + 1]) ----> ",image(every i := 1 to *a - 1 by 2 do write(image(a[i])," ",a[i + 1])) | "none")
   write("a := sort(t,4) ----> ",image(a := sort(t,4)) | "none")
   write("every i := 1 to *a - 1 by 2 do write(image(a[i]),\" \",a[i + 1]) ----> ",image(every i := 1 to *a - 1 by 2 do write(image(a[i])," ",a[i + 1])) | "none")
   write("x := [array(),table(),write,[],&input,1,\"abc\",'aa',&null] ----> ",image(x := [array(),table(),write,[],&input,1,"abc",'aa',&null]) | "none")
   write("x := sort(x) ----> ",image(x := sort(x)) | "none")
end

procedure p6()
   write("every write(image(!x)) ----> ",image(every write(image(!x))) | "none")
   write("t := table(table()) ----> ",image(t := table(table())) | "none")
   write("every t[1 to 10] := 1 do write(image(t)) ----> ",image(every t[1 to 10] := 1 do write(image(t))) | "none")
   write("t := table() ----> ",image(t := table()) | "none")
   write("every t[1 to 10] := 1 do write(*t) ----> ",image(every t[1 to 10] := 1 do write(*t)) | "none")
   write("t[] := 6 ----> ",image(t[] := 6) | "none")
   write("t[] ----> ",image(t[]) | "none")
   write("*t ----> ",image(*t) | "none")
   write("t[&null] := 7 ----> ",image(t[&null] := 7) | "none")
   write("t[] ----> ",image(t[]) | "none")
   write("*t ----> ",image(*t) | "none")
end

procedure p7()
   write("x := [] ----> ",image(x := []) | "none")
   write("*x ----> ",image(*x) | "none")
   write("every push(x,1 to 10) ----> ",image(every push(x,1 to 10)) | "none")
   write("every 1 to 10 do write(pop(x)) ----> ",image(every 1 to 10 do write(pop(x))) | "none")
   write("*x ----> ",image(*x) | "none")
   write("pop(x) ----> ",image(pop(x)) | "none")
   write("pull(x) ----> ",image(pull(x)) | "none")
   write("get(x) ----> ",image(get(x)) | "none")
   write("every put(x,1 to 10) ----> ",image(every put(x,1 to 10)) | "none")
   write("every 1 to 10 do write(get(x)) ----> ",image(every 1 to 10 do write(get(x))) | "none")
   write("every push(x,1 to 10) ----> ",image(every push(x,1 to 10)) | "none")
end

procedure p8()
   write("every 1 to 10 do write(pull(x)) ----> ",image(every 1 to 10 do write(pull(x))) | "none")
   write("x := [1,2,3,4,5,6,7,8,9,0] ----> ",image(x := [1,2,3,4,5,6,7,8,9,0]) | "none")
   write("every write(image(x[1:0 to -20 by -1])) ----> ",image(every write(image(x[1:0 to -20 by -1]))) | "none")
   write("a := [1,2,3,4,5,6,7,8] ----> ",image(a := [1,2,3,4,5,6,7,8]) | "none")
   write("a1 := a[2:4] ----> ",image(a1 := a[2:4]) | "none")
   write("a2 := a[7:2] ----> ",image(a2 := a[7:2]) | "none")
   write("a3 := a[2+:3] ----> ",image(a3 := a[2+:3]) | "none")
   write("a4 := a[-1-:3] ----> ",image(a4 := a[-1-:3]) | "none")
   write("a1[1] ----> ",image(a1[1]) | "none")
   write("a2[1] ----> ",image(a2[1]) | "none")
   write("a3[1] ----> ",image(a3[1]) | "none")
end

procedure p9()
   write("a4[1] ----> ",image(a4[1]) | "none")
   write("a4[1] := a ----> ",image(a4[1] := a) | "none")
   write("a := [1,2,3,4] ----> ",image(a := [1,2,3,4]) | "none")
   write("a1 := a[1:2] ----> ",image(a1 := a[1:2]) | "none")
   write("every write(!a1) ----> ",image(every write(!a1)) | "none")
   write("a2 := a[3:0] ----> ",image(a2 := a[3:0]) | "none")
   write("every write(!a2) ----> ",image(every write(!a2)) | "none")
   write("a4 := a[2:2] ----> ",image(a4 := a[2:2]) | "none")
   write("every write(!a4) ----> ",image(every write(!a4)) | "none")
   write("a5 := a[0-:2] ----> ",image(a5 := a[0-:2]) | "none")
   write("every write(!a5) ----> ",image(every write(!a5)) | "none")
end

procedure p10()
   write("a3 := a[0:3] ----> ",image(a3 := a[0:3]) | "none")
   write("every write(!a3) ----> ",image(every write(!a3)) | "none")
   write("a := \"abcd\" ----> ",image(a := "abcd") | "none")
   write("a1 := a[1:2] ----> ",image(a1 := a[1:2]) | "none")
   write("every write(!a1) ----> ",image(every write(!a1)) | "none")
   write("a2 := a[3:0] ----> ",image(a2 := a[3:0]) | "none")
   write("every write(!a2) ----> ",image(every write(!a2)) | "none")
   write("a3 := a[0:3] ----> ",image(a3 := a[0:3]) | "none")
   write("every write(!a3) ----> ",image(every write(!a3)) | "none")
   write("a4 := a[2:2] ----> ",image(a4 := a[2:2]) | "none")
   write("every write(!a4) ----> ",image(every write(!a4)) | "none")
end

procedure p11()
   write("a5 := a[0-:2] ----> ",image(a5 := a[0-:2]) | "none")
   write("every write(!a5) ----> ",image(every write(!a5)) | "none")
   write("[] ||| [] ----> ",image([] ||| []) | "none")
   write("[1,2,3] ||| [] ----> ",image([1,2,3] ||| []) | "none")
   write("[] ||| [1,2,3] ----> ",image([] ||| [1,2,3]) | "none")
   write("r := array(1,2,3,4,5,6,7,8,9) ----> ",image(r := array(1,2,3,4,5,6,7,8,9)) | "none")
   write("r.a ----> ",image(r.a) | "none")
   write("r.b ----> ",image(r.b) | "none")
   write("r.c ----> ",image(r.c) | "none")
   write("r.d ----> ",image(r.d) | "none")
   write("r.e ----> ",image(r.e) | "none")
end

procedure p12()
   write("r.f ----> ",image(r.f) | "none")
   write("type(r) ----> ",image(type(r)) | "none")
   write("image(r) ----> ",image(image(r)) | "none")
   write("r.a +:= 0 ----> ",image(r.a +:= 0) | "none")
   write("r.b +:= 0 ----> ",image(r.b +:= 0) | "none")
   write("r.c +:= 0 ----> ",image(r.c +:= 0) | "none")
   write("r.d +:= 0 ----> ",image(r.d +:= 0) | "none")
   write("r.e +:= 0 ----> ",image(r.e +:= 0) | "none")
   write("r.f +:= 0 ----> ",image(r.f +:= 0) | "none")
   write("r.a ----> ",image(r.a) | "none")
   write("r.b ----> ",image(r.b) | "none")
end

procedure p13()
   write("r.c ----> ",image(r.c) | "none")
   write("r.d ----> ",image(r.d) | "none")
   write("r.e ----> ",image(r.e) | "none")
   write("r.f ----> ",image(r.f) | "none")
   write("r := array(\"a\",2,array(),r,main) ----> ",image(r := array("a",2,3.5,array(),r,main)) | "none")
   write("every write(image(!r)) ----> ",image(every write(image(!r))) | "none")
   write("r[1] :=: r.d ----> ",image(r[1] :=: r.d) | "none")
   write("every write(image(!r)) ----> ",image(every write(image(!r))) | "none")
   # test that overflow is not ignored when comparing integers
   a := [847198497, -2035912587]
   every writes(" ", "a:" | !sort(a) | "\n")
end

procedure main()
   p1()
   p2()
   p3()
   p4()
   p5()
   p6()
   p7()
   p8()
   p9()
   p10()
   p11()
   p12()
   p13()
end

global s, t, x, r
global a, a1, a2, a3, a4
