New version of Main.jack in ArrayTest?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

New version of Main.jack in ArrayTest?

Marty Billingsley
One of my students just downloaded a copy of the nand2tetris software from the web site (version 2.7).

projects/10/ArrayTest/Main.jack is different from previous downloads.
However, MainT.xml is the tokenized version of the previous version, which means that tests fail.

The main difference is that the old version has two while loops, and the new version has one. Also, the old version has upper-case text while the new version has lower-case text.

Is there an updated version of MainT.xml and Main.xml to accompany the new Main.jack?


The two programs are below:
------- Old version of projects/10/ArrayTest/Main.jack (downloaded ~9/2023):
/** Computes the average of a sequence of integers. */
class Main {
    function void main() {
        var Array a;
        var int length;
        var int i, sum;
       
        let length = Keyboard.readInt("HOW MANY NUMBERS? ");
        let a = Array.new(length);
        let i = 0;
       
        while (i < length) {
            let a[i] = Keyboard.readInt("ENTER THE NEXT NUMBER: ");
            let i = i + 1;
        }
       
        let i = 0;
        let sum = 0;
       
        while (i < length) {
            let sum = sum + a[i];
            let i = i + 1;
        }
       
        do Output.printString("THE AVERAGE IS: ");
        do Output.printInt(sum / length);
        do Output.println();
       
        return;
    }
}

------- new version of projects/10/ArrayTest/Main.jack (downloaded 11/28/2023):
// Inputs some numbers and computes their average
class Main {
   function void main() {
      var Array a;
      var int length;
      var int i, sum;

      let length = Keyboard.readInt("How many numbers? ");
      let a = Array.new(length); // constructs the array
     
      let i = 0;
      while (i < length) {
         let a[i] = Keyboard.readInt("Enter a number: ");
         let sum = sum + a[i];
         let i = i + 1;
      }

      do Output.printString("The average is ");
      do Output.printInt(sum / length);
      do Output.printLn();
      return;
   }
}
Reply | Threaded
Open this post in threaded view
|

Re: New version of Main.jack in ArrayTest?

WBahn
Administrator
Thanks for reporting this issue.

I've reported this to the authors and received the following response that they asked me to relay:

"Indeed there is a mismatch problem with the files, as you mentioned. The Nand to Tetris team is aware of it and taking steps to resolve this issue. Meanwhile, use the old version of the ArrayTest/Main.jack file, attached here."

Main.jack

Reply | Threaded
Open this post in threaded view
|

Re: New version of Main.jack in ArrayTest?

WBahn
Administrator
The authors have uploaded a new version of the zip file that has a consistent set of files for ArrayTest (the old files). It also has all of the junk files that got injected into prior zip file by some Apple software along the way. This has reduced the size of the file from 4 MB down to about 1.6 MB.

Also, the project files had already been, by and large, updated for the 2nd Edition. The textbook scans are still for 1st Edition, though.