This assignment is worth 25 points.
| 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 |
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.
For example, you can use rex as an infinite-precision integer calculator:
rex > 100000000000000000 * 1000000000000000000; 100000000000000000000000000000000000 rex > 3.141592653589793 * 10; 31.4159Rex 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.
rex > add42(x) = x + 42; 1The 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); 232You 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.
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 a0at the unix prompt. ls will show you that it is there. Then, cd a0 will put you in the newly-created directory.
emacs hw0.rexwill 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).
You can run rex on your file by typing
% rex hw0.rexThis 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.
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 41This 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.
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 operatoras well as other things you might want to use ... be creative :)
rex > octuple(5.25);
42
rex > octuple(300.1);
2400.8
rex > halve(42);
21
rex > halve(41);
20.5
rex > lastdigit(42);
2
rex > lastdigit(-9678);
-8
Hint: this function is just like the previous three, except
that it uses the "mod" operator: %.
f(1) must return 7
f(2) must return 10
and
f(6) must return 42
Example input and output are
rex > f(1);
7
rex > f(2);
10
rex > f(6);
42
Keep in mind that f must not produce an error
on other inputs, but it can otherwise do anything you want!
g(h(x)) is equal to 1 + h(g(x))
Full credit will go to a solution in which the above
relationship holds for all integers. Some extra credit
will go for solutions that handle some integers, but not all.
It does not matter what your functions do for nonintegers (like
floating-point numbers).
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.
You should submit the file you create (named hw0.rex) by running from your assignment 0 directory (at the unix prompt)
% cs60submit hw0.rexYou 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.