@@ -5,16 +5,16 @@ Debug = true
55[33m[stage-9] [test-1] [0m[94mWriting contents to ./test.lox:[0m
66[33m[stage-9] [test-1] [0m[33m[test.lox][0m print clock() + 23;
77[33m[stage-9] [test-1] [0m[94m$ ./your_program.sh run test.lox[0m
8- [33m[your_program] [0m1.735294241101E9
9- [33m[stage-9] [test-1] [0m[92m✓ 1735294241.101000 [0m
8+ [33m[your_program] [0m1.738748649606E9
9+ [33m[stage-9] [test-1] [0m[92m✓ 1738748649.606000 [0m
1010[33m[stage-9] [test-1] [0m[92m✓ 1 line(s) match on stdout[0m
1111[33m[stage-9] [test-1] [0m[92m✓ Received exit code 0.[0m
1212[33m[stage-9] [test-2] [0m[94mRunning test case: 2[0m
1313[33m[stage-9] [test-2] [0m[94mWriting contents to ./test.lox:[0m
1414[33m[stage-9] [test-2] [0m[33m[test.lox][0m print clock() / 1000;
1515[33m[stage-9] [test-2] [0m[94m$ ./your_program.sh run test.lox[0m
16- [33m[your_program] [0m1735294.218204
17- [33m[stage-9] [test-2] [0m[92m✓ 1735294.218204 [0m
16+ [33m[your_program] [0m1738748.6266700001
17+ [33m[stage-9] [test-2] [0m[92m✓ 1738748.626670 [0m
1818[33m[stage-9] [test-2] [0m[92m✓ 1 line(s) match on stdout[0m
1919[33m[stage-9] [test-2] [0m[92m✓ Received exit code 0.[0m
2020[33m[stage-9] [test-3] [0m[94mRunning test case: 3[0m
@@ -321,29 +321,33 @@ Debug = true
321321[33m[stage-4] [test-2] [0m[92m✓ Received exit code 0.[0m
322322[33m[stage-4] [test-3] [0m[94mRunning test case: 3[0m
323323[33m[stage-4] [test-3] [0m[94mWriting contents to ./test.lox:[0m
324- [33m[stage-4] [test-3] [0m[33m[test.lox][0m // This program creates a function that returns another function
325- [33m[stage-4] [test-3] [0m[33m[test.lox][0m // and uses it to apply a function twice to a value
326- [33m[stage-4] [test-3] [0m[33m[test.lox][0m fun makeAdder(x) {
327- [33m[stage-4] [test-3] [0m[33m[test.lox][0m fun add(y) {
328- [33m[stage-4] [test-3] [0m[33m[test.lox][0m return x + y;
329- [33m[stage-4] [test-3] [0m[33m[test.lox][0m }
330- [33m[stage-4] [test-3] [0m[33m[test.lox][0m return add;
324+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m fun square(x) {
325+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m return x * x;
331326[33m[stage-4] [test-3] [0m[33m[test.lox][0m }
332327[33m[stage-4] [test-3] [0m[33m[test.lox][0m
333- [33m[stage-4] [test-3] [0m[33m[test.lox][0m fun applyTwice(f, x) {
334- [33m[stage-4] [test-3] [0m[33m[test.lox][0m return f(f(x));
328+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m // This higher-order function applies a
329+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m // function N times to a starting value x.
330+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m fun applyTimesN(N, f, x) {
331+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m var i = 0;
332+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m while (i < N) {
333+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m x = f(x);
334+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m i = i + 1;
335+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m }
336+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m return x;
335337[33m[stage-4] [test-3] [0m[33m[test.lox][0m }
336338[33m[stage-4] [test-3] [0m[33m[test.lox][0m
337- [33m[stage-4] [test-3] [0m[33m[test.lox][0m var addx = makeAdder(2);
338- [33m[stage-4] [test-3] [0m[33m[test.lox][0m var addy = makeAdder(2);
339- [33m[stage-4] [test-3] [0m[33m[test.lox][0m
340- [33m[stage-4] [test-3] [0m[33m[test.lox][0m print applyTwice(addx, 2);
341- [33m[stage-4] [test-3] [0m[33m[test.lox][0m print applyTwice(addy, 2);
339+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m // 2 is squared once
340+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m print applyTimesN(1, square, 2);
341+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m // 2 is squared twice
342+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m print applyTimesN(2, square, 2);
343+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m // 2 is squared thrice
344+ [33m[stage-4] [test-3] [0m[33m[test.lox][0m print applyTimesN(3, square, 2);
342345[33m[stage-4] [test-3] [0m[33m[test.lox][0m
343346[33m[stage-4] [test-3] [0m[94m$ ./your_program.sh run test.lox[0m
344- [33m[your_program] [0m6
345- [33m[your_program] [0m6
346- [33m[stage-4] [test-3] [0m[92m✓ 2 line(s) match on stdout[0m
347+ [33m[your_program] [0m4
348+ [33m[your_program] [0m16
349+ [33m[your_program] [0m256
350+ [33m[stage-4] [test-3] [0m[92m✓ 3 line(s) match on stdout[0m
347351[33m[stage-4] [test-3] [0m[92m✓ Received exit code 0.[0m
348352[33m[stage-4] [test-4] [0m[94mRunning test case: 4[0m
349353[33m[stage-4] [test-4] [0m[94mWriting contents to ./test.lox:[0m
0 commit comments