Harvey Mudd College
Computer Science 60
Assignment 0, Due Friday, Jan. 25, by midnight



Getting started with turing, UNIX, emacs, and rex!

This assignment is worth 25 points.

  1. Throughout CS 60, we will be using the Computer Science department's main computing server, named turing. An account on turing will be set up for you within a day after handing in your signed Account Request Form and the CS explanation of Mudd's Honor Code, called the Academic Honesty Policy. Be sure to read these, sign them, and hand them back by the end of class.

  2. To get your account, take your ID to Room 1240 of Olin Hall -- this is the computer science office. There, Joyce Greene will give you a sheet with your turing username and password. (Olin Hall is the big blue glass building at the west end of campus. Room 1240 is just inside the entrance in the southeast corner.)

  3. Go to the CS terminal room in Beckman B102. Beckman B102 is in the basement of Olin, on the same hallway as the eastern side of Beckman B126 (the large auditorium). (If the terminal room door is locked, you can use the combination given out in class.) Choose a terminal and get comfortable! Some of the terminals may have a "No Java" sticker on them -- those will work fine, too.

  4. Log on to turing. You will need to click "turing", enter your username, and then enter your password. A number of console windows will appear -- these are sometimes called consoles or shells. They are where commands get typed and things get done... .

  5. The very first thing to do is to change your password. To do this, simply type passwd at the prompt in one of the console windows. If you do not change your password soon (I think it's a week), your account will be disabled (because its password is on a piece of paper, which is a security risk!) You will be prompted to change your password. Your new password must Guard your password carefully!


  6. If you've changed your password, you've started using the Unix operating system. If you've used Unix or Linux before, turing will behave virtually identically. If you have not used Unix before (or would like a refresher), use netscape (just type netscape at the prompt), go to the course web page (www.cs.hmc.edu/courses/2002/spring/cs60) and follow the "Computing Resources" link. In particular, read through (and try out!) some of the tips in "Unix Basics". Here are some of the key commands to start getting familiar with:

    Command Comments
    passwd Changes your password
    netscape Fun -- even better: use netscape & to retain your shell!
    pine Pine is an email program. See the "Mail" link under "Computing Resources"
    elm Elm is another email program -- information is available from the same place
    emacs filename Edits your existing file (or creates it and starts editing)
    As with netscape, emacs & retains your command prompt.
    C-x C-c From within emacs, control-x then control-c saves your file and exits.
    pwd Prints the name of the directory you're currently in
    ls Lists the contents of your current directory
    mkdir dirname Makes a directory with name dirname
    cd dirname Changes your current directory to dirname
    A directory is equivalent to a folder in Windows/MacOS
    cd ~ Changes back to your home directory, which is named ~
    cp fromfile tofile      Makes a copy of fromfile, calling it tofile
    mv fromfile tofile Renames fromfile to be tofile. fromfile is gone.
    rm filename Removes (deletes) a file
    xterm & This command opens a new command window ("shell"), called an xterm
    lpr filename Prints a file to "gute," the printer in the terminal room


  7. In addition to Unix, the other potentially new skill that will help a great deal throughout CS 60 (and any future CS courses) is using a text editor named emacs. Emacs might have a steeper learning curve than Microsoft Word, but it has features that even Microsoft would wince at! There is a description of emacs under "Computing Resources" -- "Text Editors" from the CS 60 webpage. In addition, there will be a handout in the first class with information on emacs.

    A good thing to try first is to create a file: type emacs myfile at the unix prompt. Type some text into the file and then save it by typing control-x s within emacs or by choosing the appropriate menu item. If you then type ls at a unix prompt (in the same directory), you will see that myfile has appeared.


  8. What about programming?

    Type rex at the prompt to enter the rex interpreter. You can exit rex at any time by pressing control-d. Play around with rex and get the feel of how it works.

    For example, you can use rex as an infinite-precision integer calculator:

    rex >  100000000000000000 * 1000000000000000000;
    100000000000000000000000000000000000
    
    rex >  3.141592653589793 * 10;
    31.4159
    
    Rex has double-precision (about 15 places) for floating-point values, but only six places of precision are printed. Note that a semicolon terminates statements in rex. For lots of documentation on rex, see the rex lite reference card.

  9. As practice, write a function called add42 that takes a number as input and returns a new number that is 42 greater than the input. Here it is:
    rex >  add42(x) = x + 42;
    1
    
    The 1 basically indicates that rex is happy with your definition of the function add42. So happy, in fact, that you can now use that function:
    rex >  add42(-7);
    35
    
    rex >  add42(190);
    232
    
    You may want to try adding 42 to the string "hello":
    rex >  add42("hello");
    *** warning: can't add non-numerics k
    *** aborting to top-level
    
    As you see, rex will complain if you try to add a string to an integer.

  10. Once you've got a little bit of experience with rex, close rex. Then, at the unix prompt, type ls to see what is in your current directory in one of your shells. If you have not moved from your starting directory, there should only be one thing there: another directory named cs60. Go into this cs60 directory by typing cd cs60.

    Once there, type ls to see everything in your cs60 directory. (There will not be anything there in Spring 2002 -- this is a change from previous terms.) However, you may want to make a directory for each of your assignments. To make a directory named a0 type

      mkdir a0
    
    at the unix prompt. ls will show you that it is there. Then, cd a0 will put you in the newly-created directory.

  11. Now that you're in your assignment 0 directory, create a file to hold your answers for assignment 0. For example, typing
      emacs hw0.rex
    
    will create a file named hw0.rex and then open an emacs window to let you start editing it.

    Place your add42 function at the top of the file. You should add a comment with your name, date, and HW number, as well as a comment for your function. (Commenting in rex is identical to Java or C++.) All in all, your file will look something like this

      // CS 60 Homework 0
      // Zach Dodds 
      // 1/11/2002
      
      // Problem 1: add42 is a function that adds 42 to its input argument
    
      add42(x) = x + 42;
    
    You can save the file by choosing "save" from the appropriate menu or by typing C-x s (control-x, followed by s).

  12. Now, in a different shell (window), move (with cd) to your cs60 directory and then to your assignment 0 diurectory. Type ls and you will see your file hw0.rex is there.

    You can run rex on your file by typing

    % rex hw0.rex
    
    This will start rex and load in the file. If there are no errors, you will see the rex prompt after a message:
    hw0.rex loaded
    rex >  
    
    Now, you can test your add42 function by hand, as before.


  13. You don't have to test things by hand, however. There is a rex function named test which allows for easy testing of your functions from within a file. Add the lines (even better, copy-and-paste then from this webpage...):
      test( add42(-7), 35 );
      test( add42(0), 41 );
    
    to your hw0.rex file (emacs is still open, right?) Save the file, and in your rex window, kill rex and restart it the same way. You will see the messages
    ok: add42(-7) ==> 35
    bad: add42(0) returned 42, should be 41
    
    This way, for complicated functions, you won't have to retype or recopy tests again and again... . Of course, in this case add42 isn't wrong; instead, the problem is with the second test.

  14. The Problems

    You may be worried that you don't know enough about rex or unix or emacs to work on HW problems, but read on and (I hope) you'll find these not too bad... . Use the add42 example as a guide!

    Lots more information on using rex is available at the rex summary page. Remember -- this is only a brief introduction to rex, unix, and emacs -- next week's assignment will start to really explore the language.

    The graders will test your functions on these and other examples. When the problem states that a function's input has a given form, you may assume that the test cases will not take any other forms; that is, you do not need to put in error-checking for erroneous input types.

    Write each of the following functions in your hw0.rex file. Place at least a line of blank space between each problem and use at least one comment line (see the above example of add42 for an example of appropriate commenting).

    You will want to use these operators (perhaps they're familiar?):

       + addition
       - subtraction
       * multiplication
       / division
       % the "mod" or remainder operator
    
    as well as other things you might want to use ... be creative :)

Reading

This assignment touches on parts of Chapters 1 and 2 text, though certainly not all of Chapter 2. It's really just an introduction to the computing environment, so don't worry too much about the text (until next week!) The more you try things out, the more comfortable you will be throughout the term.

Submission

You should submit the file you create (named hw0.rex) by running from your assignment 0 directory (at the unix prompt)

% cs60submit hw0.rex
You will receive an email that shows you what you have submitted. If you would like to submit again because something went wrong, you caught an error, etc., you can always do so. Your old submission will be archived, but only the newest submission will be looked at for grading.