diff --git a/tests/bench/001-btree.buzz b/tests/bench/001-btree.buzz index 8cbecd0b..2cd69717 100644 --- a/tests/bench/001-btree.buzz +++ b/tests/bench/001-btree.buzz @@ -2,11 +2,11 @@ import "std"; import "math"; object Node { - Node? left = null, - Node? right = null, + left: Node? = null, + right: Node? = null, } -fun bottomUpTree(int depth) > Node { +fun bottomUpTree(depth: int) > Node { if (depth > 0) { return Node{ left = bottomUpTree(depth - 1), @@ -17,7 +17,7 @@ fun bottomUpTree(int depth) > Node { return Node{}; } -fun itemCheck(Node tree) > int { +fun itemCheck(tree: Node) > int { if (tree.left -> left) { return 1 + itemCheck(left) + itemCheck(tree.right!); } else { @@ -27,22 +27,22 @@ fun itemCheck(Node tree) > int { return 0; } -fun btree(int N) > void { - int mindepth = 4; - int maxdepth = mindepth + 2; +fun btree(N: int) > void { + final mindepth = 4; + var maxdepth = mindepth + 2; if (maxdepth < N) { maxdepth = N; } - int stretchdepth = maxdepth + 1; - Node stretchtree = bottomUpTree(stretchdepth); + final stretchdepth = maxdepth + 1; + final stretchtree = bottomUpTree(stretchdepth); std\print("stretch tree of depth {stretchdepth},\t check: {itemCheck(stretchtree)}"); - Node longlivedtree = bottomUpTree(maxdepth); - for (int depth = mindepth; depth < maxdepth; depth = depth + 2) { - int iterations = std\toInt(math\pow(x: 2.0, y: std\toDouble(maxdepth - depth + mindepth)) catch 0.0); - int check = 0; - for (int i = 0; i < iterations; i = i + 1) { + final longlivedtree = bottomUpTree(maxdepth); + for (depth: int = mindepth; depth < maxdepth; depth = depth + 2) { + final iterations = std\toInt(math\pow(x: 2.0, y: std\toDouble(maxdepth - depth + mindepth)) catch 0.0); + var check = 0; + foreach (_ in 0..iterations) { check = check + itemCheck(bottomUpTree(depth)); } @@ -52,8 +52,8 @@ fun btree(int N) > void { std\print("long lived tree of depth {maxdepth}\t check: {itemCheck(longlivedtree)}"); } -fun main([str] args) > void !> any { - int N = if (args.len() > 0) std\parseInt(args[0]) ?? 3 else 3; - - btree(N); +fun main(args: [str]) > void !> any { + btree( + std\parseInt(args[?0] ?? "3") ?? 3 + ); } diff --git a/tests/bench/002-merkle.buzz b/tests/bench/002-merkle.buzz index bf8d7f02..b833fac0 100644 --- a/tests/bench/002-merkle.buzz +++ b/tests/bench/002-merkle.buzz @@ -3,13 +3,13 @@ import "math"; import "errors"; object Node { - Node? left = null, - Node? right = null, - int? value = null, - int? hash = null, + left: Node? = null, + right: Node? = null, + value: int? = null, + hash: int? = null, } -fun makeTree(int depth) > Node { +fun makeTree(depth: int) > Node { if (depth > 0) { return Node{ left = makeTree(depth - 1), @@ -22,7 +22,7 @@ fun makeTree(int depth) > Node { }; } -fun check(Node tree) > bool { +fun check(tree: Node) > bool { if (tree.hash != null) { if (tree.value != null) { return true; @@ -34,7 +34,7 @@ fun check(Node tree) > bool { return false; } -fun calHash(Node tree) > void { +fun calHash(tree: Node) > void { if (tree.hash == null) { if (tree.value -> value) { tree.hash = value; @@ -47,30 +47,32 @@ fun calHash(Node tree) > void { } } -fun main([str] args) > void !> any { - int N = 6; - if (args.len() > 0) { - N = std\parseInt(args[0]) ?? 6; - } +fun main(args: [str]) > void !> any { + final N = std\parseInt(args[?0] ?? "6") ?? 6; - int mindepth = 4; - int maxdepth = mindepth + 2; + final mindepth = 4; + var maxdepth = mindepth + 2; if (maxdepth < N) { maxdepth = N; } - int stretchdepth = maxdepth + 1; - Node stretchtree = makeTree(stretchdepth); + final stretchdepth = maxdepth + 1; + final stretchtree = makeTree(stretchdepth); calHash(stretchtree); std\print("stretch tree of depth {stretchdepth}\t root hash: {stretchtree.hash ?? 0} check: {check(stretchtree)}"); - Node longlivedtree = makeTree(maxdepth); - for (int depth = mindepth; depth < maxdepth; depth = depth + 2) { - int iterations = std\toInt(math\pow(x: 2.0, y: std\toDouble(maxdepth - depth + mindepth))); - int sum = 0; - for (int i = 0; i < iterations; i = i + 1) { - Node t = makeTree(depth); + final longlivedtree = makeTree(maxdepth); + for (depth: int = mindepth; depth < maxdepth; depth = depth + 2) { + final iterations = std\toInt( + math\pow( + x: 2.0, + y: std\toDouble(maxdepth - depth + mindepth) + ) + ); + var sum = 0; + foreach (_ in 0..iterations) { + final t = makeTree(depth); calHash(t); sum = sum + t.hash ?? 0; } @@ -80,4 +82,4 @@ fun main([str] args) > void !> any { calHash(longlivedtree); std\print("long lived tree of depth {maxdepth}\t root hash: {longlivedtree.hash ?? 0} check: {check(longlivedtree)}"); -} \ No newline at end of file +} diff --git a/tests/bench/003-nbody.buzz b/tests/bench/003-nbody.buzz index 6492e37e..37d344a7 100644 --- a/tests/bench/003-nbody.buzz +++ b/tests/bench/003-nbody.buzz @@ -1,40 +1,40 @@ import "std"; import "math"; -final double pi = 3.141592653589793; -final double solarMass = 4.0 * pi * pi; -final double daysPerYear = 365.24; +final pi = 3.141592653589793; +final solarMass = 4.0 * pi * pi; +final daysPerYear = 365.24; object Body { - double x, - double y, - double z, - double vx, - double vy, - double vz, - double mass, + x: double, + y: double, + z: double, + vx: double, + vy: double, + vz: double, + mass: double, } -fun advance([Body] bodies, int nbody, double dt) > void { - for (int i = 0; i < nbody; i = i + 1) { - Body bi = bodies[i]; - double bix = bi.x; - double biy = bi.y; - double biz = bi.z; - double bimass = bi.mass; - double bivx = bi.vx; - double bivy = bi.vy; - double bivz = bi.vz; - - for (int j = i + 1; j < nbody; j = j + 1) { - Body bj = bodies[j]; - double dx = bix - bj.x; - double dy = biy - bj.y; - double dz = biz - bj.z; - double dist2 = dx * dx + dy * dy + dz * dz; - double mag = math\sqrt(dist2); +fun advance(bodies: [Body], nbody: int, dt: double) > void { + foreach (i in 0..nbody) { + final bi = bodies[i]; + final bix = bi.x; + final biy = bi.y; + final biz = bi.z; + final bimass = bi.mass; + var bivx = bi.vx; + var bivy = bi.vy; + var bivz = bi.vz; + + foreach (j in (i + 1)..nbody) { + final bj = bodies[j]; + final dx = bix - bj.x; + final dy = biy - bj.y; + final dz = biz - bj.z; + final dist2 = dx * dx + dy * dy + dz * dz; + var mag = math\sqrt(dist2); mag = dt / (mag * dist2); - double bm = bj.mass * mag; + var bm = bj.mass * mag; bivx = bivx - (dx * bm); bivy = bivy - (dy * bm); @@ -54,21 +54,21 @@ fun advance([Body] bodies, int nbody, double dt) > void { } } -fun energy([Body] bodies, int nbody) > double { - double e = 0.0; - for (int i = 0; i < nbody; i = i + 1) { - Body bi = bodies[i]; - double vx = bi.vx; - double vy = bi.vy; - double vz = bi.vz; - double bim = bi.mass; +fun energy(bodies: [Body], nbody: int) > double { + var e = 0.0; + foreach (i in 0..nbody) { + final bi = bodies[i]; + final vx = bi.vx; + final vy = bi.vy; + final vz = bi.vz; + final bim = bi.mass; e = e + (0.5 * bim * (vx * vx + vy * vy + vz * vz)); - for (int j = i + 1; j < nbody; j = j + 1) { - Body bj = bodies[j]; - double dx = bi.x - bj.x; - double dy = bi.y - bj.y; - double dz = bi.z - bj.z; - double distance = math\sqrt(dx * dx + dy * dy + dz * dz); + foreach (j in (i + 1)..nbody) { + final bj = bodies[j]; + final dx = bi.x - bj.x; + final dy = bi.y - bj.y; + final dz = bi.z - bj.z; + final distance = math\sqrt(dx * dx + dy * dy + dz * dz); e = e - ((bim * bj.mass) / distance); } } @@ -76,14 +76,14 @@ fun energy([Body] bodies, int nbody) > double { return e; } -fun offsetMomentum([Body] b, int nbody) > void { - double px = 0.0; - double py = 0.0; - double pz = 0.0; +fun offsetMomentum(b: [Body], nbody: int) > void { + var px = 0.0; + var py = 0.0; + var pz = 0.0; - for (int i = 0; i < nbody; i = i + 1) { - Body bi = b[i]; - double bim = bi.mass; + foreach (i in 0..nbody) { + final bi = b[i]; + final bim = bi.mass; px = px + (bi.vx * bim); py = py + (bi.vy * bim); @@ -95,8 +95,8 @@ fun offsetMomentum([Body] b, int nbody) > void { b[0].vz = -pz / solarMass; } -fun main([str] args) > void { - Body sun = Body{ +fun main(args: [str]) > void { + final sun = Body{ x = 0.0, y = 0.0, z = 0.0, @@ -106,7 +106,7 @@ fun main([str] args) > void { mass = solarMass, }; - Body jupiter = Body{ + final jupiter = Body{ x = 4.84143144246472090, y = -1.16032004402742839, z = -0.103622044471123109, @@ -116,7 +116,7 @@ fun main([str] args) > void { mass = 0.000954791938424326609 * solarMass, }; - Body saturn = Body{ + final saturn = Body{ x = 8.34336671824457987, y = 4.12479856412430479, z = -0.403523417114321381, @@ -126,7 +126,7 @@ fun main([str] args) > void { mass = 0.00028588598066613 * solarMass, }; - Body uranus = Body{ + final uranus = Body{ x = 12.894369562139, y = -15.111151401699, z = -0.22330757889266, @@ -136,7 +136,7 @@ fun main([str] args) > void { mass = 0.0000436624404335156298 * solarMass, }; - Body neptune = Body{ + final neptune = Body{ x = 15.379697114851, y = -25.9193146099879641, z = 0.179258772950371181, @@ -146,20 +146,17 @@ fun main([str] args) > void { mass = 0.0000515138902046611451 * solarMass, }; - [Body] bodies = [ sun, jupiter, saturn, uranus, neptune ]; + final bodies = [ sun, jupiter, saturn, uranus, neptune ]; - int N = 1000; - if (args.len() > 0) { - N = std\parseInt(args[0]) ?? 1000; - } - int nbody = bodies.len(); + final N = std\parseInt(args[?0] ?? "1000") ?? 1000; + final nbody = bodies.len(); offsetMomentum(bodies, nbody: nbody); std\print("{energy(bodies, nbody: nbody)}"); - for (int i = 0; i < N; i = i + 1) { + foreach (_ in 0..N) { advance(bodies, nbody: nbody, dt: 0.01); } std\print("{energy(bodies, nbody: nbody)}"); -} \ No newline at end of file +} diff --git a/tests/bench/004-spectral.buzz b/tests/bench/004-spectral.buzz index da1a8448..7c80dd59 100644 --- a/tests/bench/004-spectral.buzz +++ b/tests/bench/004-spectral.buzz @@ -1,64 +1,61 @@ import "std"; import "math"; -fun A(double i, double j) > double { - double ij = i + j - 1.0; +fun A(i: double, j: double) > double { + final ij = i + j - 1.0; return 1.0 / (ij * (ij - 1.0) * 0.5 + i); } -fun Av([double] x, [double] y, int N) > void { - for (double i = 0.0; i < N; i = i + 1.0) { - double a = 0.0; - for (double j = 0.0; j < N; j = j + 1.0) { +fun Av(x: [double], y: [double], N: int) > void { + for (i: double = 0.0; i < N; i = i + 1.0) { + var a = 0.0; + for (j: double = 0.0; j < N; j = j + 1.0) { a = a + x[std\toInt(j)] * A(i: i, j: j); } y[std\toInt(i)] = a; } } -fun Atv([double] x, [double] y, int N) > void { - for (double i = 0.0; i < N; i = i + 1.0) { - double a = 0.0; - for (double j = 0.0; j < N; j = j + 1.0) { +fun Atv(x: [double], y: [double], N: int) > void { + for (i: double = 0.0; i < N; i = i + 1.0) { + var a = 0.0; + for (j: double = 0.0; j < N; j = j + 1.0) { a = a + x[std\toInt(j)] * A(i: j, j: i); } y[std\toInt(i)] = a; } } -fun AtAv([double] x, [double] y, [double] t, int N) > void { +fun AtAv(x: [double], y: [double], t: [double], N: int) > void { Av(x: x, y: t, N: N); Atv(x: t, y: y, N: N); } -fun main([str] args) > void { - int N = 100; - if (args.len() > 0) { - N = std\parseInt(args[0]) ?? 100; - } +fun main(args: [str]) > void { + final N = std\parseInt(args[?0] ?? "100") ?? 100; - [double] u = []; - [double] v = []; - [double] t = []; - for (int i = 0; i < N; i = i + 1) { + final u = []; + final v = []; + final t = []; + foreach (_ in 0..N) { u.append(1.0); v.append(0.0); t.append(0.0); } - for (int i = 0; i < 10; i = i + 1) { + foreach (_ in 0..10) { AtAv(x: u, y: v, t: t, N: N); AtAv(x: v, y: u, t: t, N: N); } - double vBv = 0.0; - double vv = 0.0; - for (int i = 0; i < N; i = i + 1) { - double ui = u[i]; - double vi = v[i]; + var vBv = 0.0; + var vv = 0.0; + foreach (i in 0..N) { + final ui = u[i]; + final vi = v[i]; vBv = vBv + ui * vi; vv = vv + vi * vi; } std\print("{math\sqrt(vBv / vv)}"); -} \ No newline at end of file +} diff --git a/tests/bench/005-k-nucleoide.buzz b/tests/bench/005-k-nucleoide.buzz index 55e7c27d..f0714355 100644 --- a/tests/bench/005-k-nucleoide.buzz +++ b/tests/bench/005-k-nucleoide.buzz @@ -3,15 +3,15 @@ import "io"; import "errors"; fun readSequence() > str !> errors\ReadWriteError, errors\FileSystemError, errors\UnexpectedError { - bool skippedIgnoredSequences = false; - [str] lines = []; - for (str? line = ""; line != null; line = io\stdin.readLine()) { // catch null doesn't work + var skippedIgnoredSequences = false; + final lines = []; + for (line: str? = ""; line != null; line = io\stdin.readLine()) { // catch null doesn't work if (!skippedIgnoredSequences) { if (line?.startsWith(">THREE") ?? true) { skippedIgnoredSequences = true; } } else { - str c = line?[0] ?? "_"; + final c = line?[0] ?? "_"; if (c == ">") { break; } else if (c != ";") { @@ -23,38 +23,38 @@ fun readSequence() > str !> errors\ReadWriteError, errors\FileSystemError, error return lines.join("").upper(); } -fun kfrequency(str sequence, {str: int} frequency, int k, int frame) > void { - for (int i = frame; i < sequence.len(); i = i + k) { - str c = sequence.sub(i, len: k); +fun kfrequency(sequence: str, frequency: {str: int}, k: int, frame: int) > void { + for (i: int = frame; i < sequence.len(); i = i + k) { + final c = sequence.sub(i, len: k); frequency[c] = (frequency[c] ?? 0) + 1; } } -fun count(str sequence, str fragment) > void { - final int k = fragment.len(); - {str: int} frequency = {}; - for (int frame = 0; frame < k; frame = frame + 1) { +fun count(sequence: str, fragment: str) > void { + final k = fragment.len(); + final frequency = {}; + for (frame: int = 0; frame < k; frame = frame + 1) { kfrequency(sequence, frequency: frequency, k: k, frame: frame); } std\print("{frequency[fragment] ?? 0}\t{fragment}"); } -fun frequency(str sequence, int k) > void { - {str: int} frequency = {}; - for (int frame = 0; frame < k; frame = frame + 1) { +fun frequency(sequence: str, k: int) > void { + final frequency = {}; + for (frame: int = 0; frame < k; frame = frame + 1) { kfrequency(sequence, frequency: frequency, k: k, frame: frame); } - int sum = sequence.len() - k + 1; - foreach (str c, int f in frequency) { + final sum = sequence.len() - k + 1; + foreach (c, f in frequency) { std\print("{c} {(f * 100) / sum}"); } std\print(""); } // buzz tests/bench/005-k-nucleoide.buzz < tests/bench/reference/knucleotide-input.txt -fun main([str] _) > void { - str sequence = readSequence() catch ""; +fun main(_: [str]) > void { + final sequence = readSequence() catch ""; frequency(sequence, k: 1); frequency(sequence, k: 2); count(sequence, fragment: "GGT"); @@ -62,4 +62,4 @@ fun main([str] _) > void { count(sequence, fragment: "GGTATT"); count(sequence, fragment: "GGTATTTTAATT"); count(sequence, fragment: "GGTATTTTAATTTATAGT"); -} \ No newline at end of file +} diff --git a/tests/bench/006-fasta.buzz b/tests/bench/006-fasta.buzz index fd984011..3eda7388 100644 --- a/tests/bench/006-fasta.buzz +++ b/tests/bench/006-fasta.buzz @@ -2,37 +2,37 @@ import "std"; import "math"; import "buffer" as _; -final double IM = 139968.0; -final double IA = 3877.0; -final double IC = 29573.0; -final int lineLength = 60; -final int bufferSize = (lineLength + 1) * 1024; +final IM = 139968.0; +final IA = 3877.0; +final IC = 29573.0; +final lineLength = 60; +final bufferSize = (lineLength + 1) * 1024; -fun makeRepeatFasta(str id, str desc, str s, int nchars) > void { +fun makeRepeatFasta(id: str, desc: str, s: str, nchars: int) > void { std\print(">{id} {desc}"); - int p = 0; - int sn = s.len(); - str s2 = s + s; - for (int i = lineLength; i < nchars; i = i + lineLength) { + var p = 0; + final sn = s.len(); + final s2 = s + s; + for (i: int = lineLength; i < nchars; i = i + lineLength) { std\print(s2.sub(p, len: lineLength - 1)); p = p + lineLength; if (p > sn) { p = p - sn; } } - int tail = nchars % lineLength; + final tail = nchars % lineLength; if (tail > 0) { std\print(s2.sub(p, len: tail - 1)); } } object Frequency { - Buffer chars, - [double] probs, - double last, + chars: Buffer, + probs: [double], + last: double, - static fun init(Buffer chars, [double] probs, double last) > Frequency { - Frequency freq = Frequency{ + static fun init(chars: Buffer, probs: [double], last: double) > Frequency { + final freq = Frequency{ chars = chars, probs = probs, last = last, @@ -43,29 +43,29 @@ object Frequency { return freq; } - fun random(double max) > double { + fun random(max: double) > double { this.last = (this.last * IA + IC) % IM; return max * this.last * (1.0 / IM); } fun makeCumulative() > void { - double cp = 0.0; - foreach (int i, double prob in this.probs) { + var cp = 0.0; + foreach (i, prob in this.probs) { cp = cp + prob; this.probs[i] = cp; } } - fun selectRandomIntoBuffer(Buffer buffer, int initialBufferIndex, int nRandom) > int !> OutOfBoundError, WriteWhileReadingError { - final int len = this.probs.len(); + fun selectRandomIntoBuffer(buffer: Buffer, initialBufferIndex: int, nRandom: int) > int !> OutOfBoundError, WriteWhileReadingError { + final len = this.probs.len(); var bufferIndex = initialBufferIndex; - for (int rIndex = 0; rIndex < nRandom; rIndex = rIndex + 1) { - double r = this.random(1.0); - bool skip = false; - for (int i = 0; i < len; i = i + 1) { + foreach (_ in 0..nRandom) { + final r = this.random(1.0); + var skip = false; + foreach (_ in 0..len) { if (r < this.probs[i]) { - buffer\setAt(bufferIndex, value: this.chars.at(i)); + buffer.setAt(bufferIndex, value: this.chars.at(i)); bufferIndex = bufferIndex + 1; skip = true; break; @@ -73,7 +73,7 @@ object Frequency { } if (!skip) { - buffer\setAt(bufferIndex, value: this.chars.at(len - 1)); + buffer.setAt(bufferIndex, value: this.chars.at(len - 1)); bufferIndex = bufferIndex + 1; } } @@ -82,32 +82,32 @@ object Frequency { } } -fun makeRandomFasta(str id, str desc, Frequency fpf, int initialNchars) > void !> OutOfBoundError, WriteWhileReadingError { +fun makeRandomFasta(id: str, desc: str, fpf: Frequency, initialNchars: int) > void !> OutOfBoundError, WriteWhileReadingError { std\print(">{id} {desc}"); var nchars = initialNchars; - Buffer buffer = Buffer.init(bufferSize); - int bufferIndex = 0; + var buffer = Buffer.init(bufferSize); + var bufferIndex = 0; while (nchars > 0) { - int chunkSize = std\toInt(math\minDouble(a: std\toDouble(lineLength), b: std\toDouble(nchars))); + final chunkSize = std\toInt(math\minDouble(a: std\toDouble(lineLength), b: std\toDouble(nchars))); if (bufferIndex == bufferSize) { - std\print(buffer\toString().sub(0, len: bufferIndex)); + std\print(buffer.toString().sub(0, len: bufferIndex)); buffer = Buffer.init(bufferSize); bufferIndex = 0; } bufferIndex = fpf.selectRandomIntoBuffer(buffer, initialBufferIndex: bufferIndex, nRandom: chunkSize); - buffer\setAt(bufferIndex, value: 10); + buffer.setAt(bufferIndex, value: 10); bufferIndex = bufferIndex + 1; nchars = nchars - chunkSize; } - std\print(buffer\toString().sub(0, len: bufferIndex)); + std\print(buffer.toString().sub(0, len: bufferIndex)); } -final str alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +final alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" @@ -115,17 +115,14 @@ final str alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; -fun main([str] args) > void !> any { - int N = 1000; - if (args.len() > 0) { - N = std\parseInt(args[0]) ?? 1000; - } +fun main(args: [str]) > void !> any { + final N = std\parseInt(args[?0] ?? "1000") ?? 1000; makeRepeatFasta("ONE", desc: "Homo sapiens alu", s: alu, nchars: N * 2); - Buffer iubChars = Buffer.init(); + final iubChars = Buffer.init(); iubChars.write("acgtBDHKMNRSVWY"); - final Frequency iub = Frequency.init( + final iub = Frequency.init( chars: iubChars, probs: [ 0.27, 0.12, 0.12, 0.27, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02 ], last: 42.0, @@ -133,13 +130,13 @@ fun main([str] args) > void !> any { makeRandomFasta("TWO", desc: "IUB ambiguity codes", fpf: iub, initialNchars: N * 3); - Buffer homoSapiensChars = Buffer.init(); + final homoSapiensChars = Buffer.init(); homoSapiensChars.write("acgt"); - final Frequency homoSapiens = Frequency.init( + final homoSapiens = Frequency.init( chars: homoSapiensChars, probs: [ 0.3029549426680, 0.1979883004921, 0.1975473066391, 0.3015094502008 ], last: iub.last, ); makeRandomFasta("THREE", desc: "Homo sapiens frequency", fpf: homoSapiens, initialNchars: N * 5); -} \ No newline at end of file +} diff --git a/tests/bench/007-fib.buzz b/tests/bench/007-fib.buzz index 90f8ff95..54bbfd8c 100644 --- a/tests/bench/007-fib.buzz +++ b/tests/bench/007-fib.buzz @@ -1,6 +1,6 @@ import "std"; -fun fibonnacci(int n) > int { +fun fibonnacci(n: int) > int { if (n < 2) { return n; } @@ -8,6 +8,6 @@ fun fibonnacci(int n) > int { return fibonnacci(n - 2) + fibonnacci(n - 1); } -fun main([str] _) > void { +fun main(_: [str]) > void { std\print("{fibonnacci(30)}"); -} \ No newline at end of file +} diff --git a/tests/bench/008-for.buzz b/tests/bench/008-for.buzz index a373ecac..fc24a869 100644 --- a/tests/bench/008-for.buzz +++ b/tests/bench/008-for.buzz @@ -1,16 +1,16 @@ import "std"; -fun main([str] _) > void { - [int] list = []; +fun main(_: [str]) > void { + final list = []; - for (int i = 0; i < 1000000; i = i + 1) { + foreach (i in 0..1_000_000) { list.append(i); } - int sum = 0; - foreach (int v in list) { + var sum = 0; + foreach (v in list) { sum = sum + v; } std\print("{sum}"); -} \ No newline at end of file +} diff --git a/tests/bench/009-grid.buzz b/tests/bench/009-grid.buzz index e868c032..14a7c13d 100644 --- a/tests/bench/009-grid.buzz +++ b/tests/bench/009-grid.buzz @@ -1,18 +1,18 @@ import "std"; -fun main([str] args) > void { - final int width = (if (args.len() > 0) std\parseInt(args[0]) else 80) ?? 80; - final int height = (if (args.len() > 1) std\parseInt(args[1]) else 60) ?? 60; +fun main(args: [str]) > void { + final width = std\parseInt(args[?0] ?? "80") ?? 80; + final height = std\parseInt(args[?1] ?? "60") ?? 60; var cells = []; - for (int i = 0; i < width * height; i = i + 1) { + foreach (_ in 0..width * height) { cells.append(std\random(max: 5) == 1); } - for (int y = 0; y < height; y = y + 1) { - for (int x = 0; x < width; x = x + 1) { + foreach (y in 0..height) { + foreach (x in 0..width) { cells[y * width + x] = !cells[y * width + x]; } } -} \ No newline at end of file +} diff --git a/tests/bench/010-ackermann.buzz b/tests/bench/010-ackermann.buzz index 812ba43c..808b761c 100644 --- a/tests/bench/010-ackermann.buzz +++ b/tests/bench/010-ackermann.buzz @@ -1,13 +1,13 @@ import "std"; -fun main([str] args) > void { - final m = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 3; - final n = (if (args.len() > 1) std\parseInt(args[1]) else null) ?? 8; +fun main(args: [str]) > void { + final m = std\parseInt(args[?0] ?? "3") ?? 3; + final n = std\parseInt(args[?1] ?? "8") ?? 8; std\print("result: {ack(m, n)}"); } -fun ack(int m, int n) > int { +fun ack(m: int, n: int) > int { if (m == 0) { return n + 1; } @@ -20,4 +20,4 @@ fun ack(int m, int n) > int { m: m - 1, n: ack(m, n: n - 1) ); -} \ No newline at end of file +} diff --git a/tests/bench/011-bubble-sort.buzz b/tests/bench/011-bubble-sort.buzz index a5e8c669..94812940 100644 --- a/tests/bench/011-bubble-sort.buzz +++ b/tests/bench/011-bubble-sort.buzz @@ -1,33 +1,33 @@ import "std"; -fun main([str] args) > void { - final max = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 750; +fun main(args: [str]) > void { + final max = std\parseInt(args[?0] ?? "750") ?? 750; var list = init(max); bubblesort(list); - foreach (int e in list) { + foreach (e in list) { std\print("{e}"); } } -fun init(int max) > [int] { - [int] list = []; +fun init(max: int) > [int] { + final list = []; final f = max - 13; final h = ((max - 117) * (max - 13)) / max; - for (int i = 0; i < max; i = i + 1) { + foreach (i in 0..max) { list.append((f * i) % h - (h / 2)); } return list; } -fun bubblesort([int] list) > void { +fun bubblesort(list: [int]) > void { final len = list.len(); - for (int i = 0; i < len - 1; i = i + 1) { - for (int j = 0; j < len - 1; j = j + 1) { + foreach (_ in 0..(len - 1)) { + foreach (j in 0..(len - 1)) { if (list[j] > list[j + 1]) { final tmp = list[j]; list[j] = list[j + 1]; @@ -35,4 +35,4 @@ fun bubblesort([int] list) > void { } } } -} \ No newline at end of file +}