CMPU 101 Section 55, Spring 2019 Lab 0 Part 0: Logging on and changing your password --------------------------------------------- [Jerry, our system administrator, will walk you through this.] Log into your account using the following information: Username: The same as the username in your Vassar email address Password: Check the front of the classroom Open a web browser -- a button to launch Firefox should be on the top panel -- and load https://www.cs.vassar.edu/help/password Follow the link at the top of that page to change your password. The only requirement is that your new password needs to be 16 characters. Log out by click the gear icon next to the date in the top panel and selecting "Log Out..." and log back in using the new password to check that it worked. ---- The purpose of this lab is to help you set up your Vassar CS Dept account, familiarize yourself with running DrRacket (the application we'll use throughout the semester for programming), and the process for saving and submitting your work. You'll access your CS account through computers running the Linux operating system. In this lab, you'll encounter some of the basic Linux commands you can use. After you finish each part, ask the professor or coach to check it off. If you get stuck anywhere along the line, please ask for help! Part 1: Working with directories on the command line ---------------------------------------------------- While Linux has a graphical user interface like you're used to, much of its power comes from using the traditional command line interface. You can interact with this using a terminal window. To open a terminal, either: - Use the menu: Menu -> System Tools -> MATE Terminal - Use the shortcut: Ctrl-Alt-T Working in the terminal is a bit like playing with Logo: You type commands, and when you hit the Enter key, the system executes them -- but instead of moving the Turtle, we'll be interacting with the operating system. It's helpful to keep different files (e.g., lab work, assignments) separate, so we'll create a new directory for today's lab work. At the command prompt, type: pwd and press enter. "pwd" is a Linux command that stands for "print working directory". It tells you where you are in the file system, which should be /home//. This is your home directory. The working directory is also displayed in the command prompt, but it abbreviates your home directory to just a tilde ("~"). Now type: mkdir lab0 and press enter. "mkdir" stands for "make directory", and that's what it does! Now type ls and press enter. In addition to the default directories ("Desktop", "Documents", etc.), you should see the "lab0" directory you just created. "ls" is a Linux command that stands for "list"; it lists the files in the current directory. Now type cd lab0 and press enter. The "cd" command, as you might have guessed, stands for "change directory". If you use the "ls" command now you'll just get the command prompt back. This is because this directory is empty, so let's make a file! Part 2: Using DrRacket ---------------------- In the terminal, type drracket & (The "&" tells Linux to "run it in the background". Otherwise, you wouldn't be able to keep using the terminal while DrRacket was running. The numbers printed in the terminal after you do this are the system's job and process IDs; you don't need to worry about them.) When DrRacket loads, you'll be presented with a window divided into two main frames: the Definitions Window on the top and the Interactions Window on the bottom. To be friendly, DrRacket greets you with an error, telling you that you need to select a programming language. Use the "Language" menu to "Choose Language" and select "The Racket Language". DrRacket will add the line #lang racket to the Definitions Window. To put this choice into effect, press the "Run" button in the upper right. Now we can play! In the Interactions Window, type: 1 and press enter. This input gets evaluated and -- fascinatingly -- the result is also the number 1! Let's be a bit braver and try the following: (+ 1 2 3) and press enter. Hopefully the answer is 6! Just like when we were playing with Logo, we're using a built-in function, "+", which is immediately evaluated. The function comes first, followed by its inputs, and the entire expression is wrapped in parentheses. We can also define our own functions in the Definitions Window above, but first let's set up DrRacket a bit better: Open DrRacket's preferences window ("Edit" -> "Preferences...") and then click on the "Editing" and "General Editing" tabs. Enable the "Maximum character width guide" with a value of "80". This means that when you type lines that are more than 80 characters long, DrRacket will draw a vertical line to communicate my displeasure. Feel free to try other preferences you like, e.g., you can change the font and color scheme to whatever you find comfortable. Now, in the Definitions Window, type the following below the "#lang racket" line: (define pythag (lambda (x y) (sqrt (+ (* x x) (* y y))))) (define x 15) (define y 112) Please type this out rather than copying and pasting. Note that DrRacket indents the code for you, reflecting the structure of what we're writing. Take care that you have the right number of parentheses. When you type closing (right) parentheses, DrRacket will highlight the match to make it easier. Don't worry that you don't understand everything you just typed -- we haven't covered it yet! We'll start exploring the meaning of all this in class next week. For now we're just getting comfortable working with DrRacket on Linux. (Though, as you might guess, "sqrt" is short for "square root", and + and * are addition and multiplication respectively!) Notice that nothing is evaluated when you enter this. We're defining a function and two values to use later. Once you've done that, click the "Run" button again. Now, in the interactions window, type (pythag x y) and the computer should respond: 113 You've now created a new function to compute the Pythagorean theorem: If x (15) and y (112) are sides of a triangle, the third side needs to be of length 113. While you've given names -- the variables x and y -- to two values, you can call this function on any numbers, e.g., (pythag 10 20) Part 3: Saving and Loading Your Work ------------------------------------ To save your work, select "File" -> "Save Definitions As..." A save box will appear, with a list of directories in your home directory. If the save dialog isn't already in the "lab0" directory, navigate to it. Enter a name for the file in the input box at the top, where the cursor is blinking. Use the name "-lab0-defns.rkt". ("defns" is short for "definitions". "rkt" is one of the file extensions used for Racket code; "txt" is also fine.) Click "Save". The window will disappear. Go to the terminal window and type "ls" and press enter. Now the computer should display the name of the file you just saved. Now that you're sure your work has been saved, close DrRacket by clicking on the "X" in the upper right corner of the window or using the "File" -> "Quit" menu item. DrRacket will check if you're sure; it's a bit clingy. Run the program again and use the "File" -> "Open..." menu to load your work from the file where you saved it. When you do this, the contents should appear in the Definitions Window, and the Interactions Window will be hidden. You can think about the Interactions Window as your scratch paper, where you can try things out, but it disappears when you're done. Click the "Run" button again. The Interactions Window will appear and you can once again run your function: (pythag x y) The computer should still respond "113". The program saved correctly and still works. Let's save this interaction to demonstrate how the code works. Click on the "File" menu and select "Save Other" -> "Save Interactions as Text...". Put this in your "lab0" directory, with the name "-lab0-inters.txt". This is just a transcript of interacting with Racket, not code that we can run, so it has the plain-text ".txt" file extension. If you want to check that this file saved correctly, in the terminal you can run: more -lab0-inters.txt and it will print the contents of the file. Part 4: Submitting your work ---------------------------- To submit a lab or assignment electronically, you should be in the parent directory of the one you want to submit. Since your "lab0" directory is in your home directory, this is where you want to be. To return to the home directory, just type "cd" with no argument. Use "pwd" to check that you're now in /home/. Now type submit101 g-lab0 lab0 The first argument is the name of the dropbox you're submitting to -- the "g" is for "Gordon" -- and "lab0" is the name of the directory you're submitting. If you see a bunch of hopeful messages fly by, it probably worked, but you should ask me or your coach to check! Coda ---- When you want to print your work, make sure it's saved and then from the terminal, for a file named "myfile.txt", type: enscript -P Asprey myfile.txt This will send it to the printer in the lab (SP 307). "Asprey" is the name of the printer in there. Note: Only use "enscript" to print plain-text files like we saved in this lab; it won't work for other kinds of files (and might print pages of gibberish). To save some trees, you don't need to print your lab work today, but you may be asked to print your assignment submissions in future. When you're done, be sure to log out! That's it!