Com S 227 --- Introduction to Computer Programming HOMEWORK 0: GETTING STARTED (File $Date: 1993/09/03 22:24:36 $) Due: problems 1-3, Aug. 25; 4-12, Aug. 27; 13-18, Aug. 30. In this homework, you will be getting started on Unix (Project Vincent), learning how to edit files, creating some basic files for your account, learning how to print files, learning how to send and receive electronic mail (e-mail), and learning how to run Scheme programs and get a transcript. The section headings below give the names of handouts or sections in the ``User's Guide to Project Vincent'' that you should read to help yourself with the problems. VINCENT ACCOUNT INFORMATION SHEET, USER'S GUIDE TO PROJECT VINCENT: 3.1 1. (10 points; basic) Obtain a Project Vincent user account. If you have trouble (this is not at all unusual if you just arrived at ISU), note the message and go to 197 Durham. If you cannot complete this by the due date, let us know you are having problems, and hand this problem in as soon as you get your account. Then write down on a piece of paper your family name, your given name, the last 6 digits of your University ID number (i.e. your social security number), your Project Vincent login ID, your local phone number (if you have one), and time of the discussion/lab section for which you signed up. The format should look like the following example Family Name Given Name Last 6 of ID login Phone Section Leavens, Gary 123456 leavens 294-1580 Tues. 11 We will use this information for grading reports, class lists, and as a means to contact you. (We won't let anyone see your phone number except the course staff.) USER'S GUIDE TO PROJECT VINCENT: 3.2-3.5, LEARNING VINCENT INTERACTIVELY 2. (0 points; basic) On a Project Vincent workstation, run the abc lesson for Vincent, as described in the handout ``Learning Vincent Interactively''. You will need a workstation for this. (If you can't get access to a workstation, continue on below. Some of the other problems will give you practice you would get from the on-line workshop. But it is best to do this on a workstation.) This on-line workshop covers the basics of files, vincent commands, emacs, and e-mail. Skip the part about ``compiling, linking and running.'' EMACS REFERENCE CARD, USER'S GUIDE TO PROJECT VINCENT: 4.1--4.2 3. (0 points; basic) It is important now to learn more about the emacs editor. To run the emacs tutorial, start the emacs program by typing emacs and a return at the vincent prompt. Run the on-line tutorial for emacs by typing control-h, then a ``t'', and then following directions. This will take a while, but be sure to work through the tutorial carefully. You can go quickly over what you already learned from the abc lessson on Vincent. You do not need a workstation for this, but if you are not using a workstation, be sure that you read the information in the handout ``Getting to and Using Project Vincent without a Workstation'' in the sections about using the ISN and emacs. If you do that, you'll have to remember that where the tutorial says C-s, you will type C-\ , and where it says C-q, you will type C-^. (If that's confusing, just find a workstation for now.) If you already know emacs or if you are going to, against our advice, use another Unix editor (e.g., vi) you may skip this problem. 4. (5 points; extra credit) a. What does M-x mean to emacs? What different ways can you use to type it? b. What are the commands for moving up and down in a buffer without using the cursor (arrow) keys? c. What do you type in emacs to cancel a command? d. What sequence of commands do you type in emacs to move a line from one place to another? e. How do you undo mistakes in emacs? f. How do you create a file using emacs? g. What are the names of the commands in emacs apropos ``scheme''? h. What does the emacs command C-x 4 f do? USER'S GUIDE TO PROJECT VINCENT: 4.1--4.2, 3.4.7--3.4.8, 3.4.15, 3.5, The problems in this section are vital and must be done in order. If you can't get them to work, ask a member of the staff, right away! 5. (3 points; basic) The first thing to do is to give you access to some Vincent ``lockers''. Create a file ~/.startup.tty by editing it to contain the following lines # Add the Chez Scheme locker, so I can run Chez Scheme # The -n tells add (really attach) not to authenticate me. add -n scheme # Add the Com S 227 locker, so I can get the course files add cs227 (Don't remember how to create a file? Go back to problem 3.) (Don't have permission to create the file? You're in the wrong directory.) Check that your file ends in a newline, by typing cat .startup.tty; if the prompt for the next Unix command does not start in the usual place, you are missing a newline: edit the file and hit ``return'' after the last character in the file. Check that the file is exactly as shown, except that the lines start at the left margin. Computer programming requires a great deal of precision typing, and this is practice for it, even though the lines that start with # are comments. In Unix, files whose names start with a dot (.) are hidden and not shown by a normal ``ls'' command. To show them use ls -a. Try ls -a now. Log out and then log in again. Check that now you can start Chez Scheme by typing scheme at the Vincent prompt. When Scheme starts running, type (expt 2 0.5) to it. Be sure to hit ``return'' afterwards. What does it print? You are welcome to play with it more at this point, but we will move on for now. Type (exit) or C-d to get out of Scheme. When your file is complete, print it, and hand in a copy to your TA. (More details on the following material in this section is found in the file /home/cs227/doc/running-scheme.txt on project Vincent.) 6. (5 points) Create a file ~/.emacs so that it contains the following lines. ;; tell emacs where to find the emacs-lisp files (setq load-path (cons "/home/cs227/emacs" load-path)) ;;; tell emacs what files should be loaded for what commands (autoload 'run-scheme "cmuscheme" "Run Scheme in an emacs buffer." t) (autoload 'scheme-mode "cmuscheme" "Mode for Scheme programming and interaction" t) ;;; define special behavior that I want for scheme program files (setq scheme-mode-hook '((lambda () (setq scheme-mit-dialect nil) (define-key scheme-mode-map "\n" 'newline) (define-key scheme-mode-map "\r" 'newline-and-indent)))) ;;; tell emacs that files that end in .ss are Chez Scheme files. (setq auto-mode-alist (append '(("\\.ss$" . scheme-mode)) auto-mode-alist)) Note that the double quotes " are single characters. The above lines are in Emacs-LISP, which resembles Scheme. Check that you typed these lines in correctly by starting a fresh emacs, editing a file named foo.ss, and checking that you are in Scheme mode in the buffer for that file. (If you get the message ``Error in init file'' from emacs, you have made a typing mistake in this.) In Scheme mode, look at the output of C-h m (control-h then ``m''). Note that tabs make Scheme indent code. Hand in a printout of your .emacs file. (This is required even if you use some other editor.) 7. (5 points; basic) To get the course customization of Chez Scheme you will create a shell script file that has Scheme load /home/cs227/lib/springer-friedman.ss whenever it is run. You don't have to understand how the following does that. Make a directory, called bin for historical reasons, to contain the Unix shell script that will be made below. mkdir ~/bin Now create a file ~/bin/scheme that contains the following line. exec /home/scheme/bin/dec/scheme /home/cs227/lib/springer-friedman.ss $* Be sure that there is a newline following this line. That is, if emacs asks you if you want one, answer yes. Note carefully each of the spaces (blanks) in the above line. Check to make sure you typed it exactly as written here. Change the unix file mode (permissions) on the file you just created to make it executable. To do this execute the following commands from the Vincent Shell. cd ~/bin chmod +rx scheme cd The cd (change directory) command changes your shell's current working directory. When given no arguments, it returns you to your home directory. To check that this has been set up properly, try the following from the Vincent shell. rehash which scheme echo ~/bin/scheme The responses to the last 2 commands should be the same. If they are not, see a member of the course staff. Hand in a printout of your file ~/bin/scheme. 8. (10 points; basic) It's time to use emacs or a printer to find out more about the course. Write brief answers to the following questions on a piece of paper and hand them in. a. Change to the directory /home/cs227. (If you can't do that, go back to problem 5 and make sure you have that correct.) What are the names of the directories in /home/cs227? b. One of the directories in /home/cs227 is called doc. Change to that directory. In the file course-spec.txt is the ``Course Specification''. What are the essential objectives of the course? c. In what file in /home/cs227/doc is the course syllabus? When is the date of the final exam for the course? d. In the file /home/cs227/doc/red-tape.txt is the ``Course Policies and Procedures'' document. Do you have to buy the book ``The Little LISPer''? What is the policy on late homework? What is the difference between cheating and cooperation? You may want to print your own copy of the syllabus and the ``Course Policies and Procedures'' document. 9. (0 points; suggested practice) Use emacs to read the other files in the directory /home/cs227/doc. 10. (0 points; suggested practice) To give you more practice with emacs and to personalize your environment more, try the following. a. The news readers on Project Vincent, and some other programs use a file named ~/.signature. Create a file .signature in your home directory. It should contain your street address, your e-mail address, and (if you wish) your phone number. It should be no more than 3 lines long. b. The .cshrc.mine file in your home directory can be used to customize the Unix shell. Create this file and put in it the following line. alias rm 'rm -i' Make sure the file ends in a newline. This says to make the rm command (for removing files) always ask for confirmation; it may save your neck sometime. Another useful one is the following. alias pwd 'echo $cwd' This makes pwd give you shorter strings. If you are a DOS user, you can put other lines in the file to alias your favorite DOS commands to their Unix equivalents. For example, you might want to use the following. alias dir ls alias copy cp alias rename mv c. The ``finger'' program on Project Vincent can be used to locate people. For example, try finger leavens@iastate.edu to see who user ``leavens'' is. What happens when you do the following? finger gary@iastate.edu Use the finger command on yourself to see if it has the information correct. Use the ``chfn'' command to change the information in the top part (before the words Plan:) if it is incorrect or missing. See the manual page for ``finger'' and page 34 of the ``User's Guide to Project Vincent''. On Vincent, the finger command prints a file, ~/.plan when someone on the same machine as you uses finger to locate you. You can put whatever you like in this file, but it typically should include the same kind of information as in your .signature file, and in addition a few witty sayings or some other stuff you want people to learn about you. Try finger leavens@ren.cs.iastate.edu for an example. Try fingering your friends. After you make a ~/.plan file, you must make it readable by others for the ``finger'' command to use it. To do this type the following chmod +r ~/.plan to the Vincent prompt. Also note that your .plan file does not immediately show up to ``finger''; on Vincent there is a program that runs every night that collects these files, so you'll have to wait a day to see it. USER'S GUIDE TO PROJECT VINCENT: 11.1 11. (0 points; suggested practice) If you didn't work with e-mail in the On-line Workshop to Project Vincent, go back and do that. Alternatively, send a message to yourself. Start an e-mail message to yourself as described in section 11.1.6. Check your mail to yourself by reading it as described in section 11.1.3 of the ``User's Guide to Project Vincent''. 12. (5 points; basic) Your TA will send you a piece of e-mail (after you have told them your login id). Reply to it by e-mail as directed in the message. Be sure to include a subject and a signature. (The subject and signature are important for the reader of your mail. I've often gotten mail from students without a signature, from whom I then have no idea who they are until I look up their login id in my files.) Send a carbon copy to yourself, so that you have a record of the message in case it gets lost. USER'S GUIDE TO PROJECT VINCENT: 12.1, 3, 15 13. (5 points; extra credit) Use emacs to read the file ``/home/cs227/doc/reading-news.txt''. Create the files that are suggested and try reading the news for our class. There should be a message whose summary is: ``the message for HW0''. Read that message, and carry out its instructions for your credit. 14. (3 points; extra credit) Post the message ``I can read the news'', to our news group, with subject ``can read, my section is
'', where you should replace ``
'' with your discussion section time (e.g., M10), and summary ``I can read it''. Be sure to sign your name. Make sure you have a .signature file (as described above) before you do this problem. 15. (0 points; suggested practice) Read the rest of chapter 3 (Basic Ultrix), and chapter 15 (Identifying and Reporting Problems) of the ``User's Guide to Project Vincent''. 16. (0 points; suggested practice) Use emacs to type in homework for another class you are taking. Print it and see how impressed your teacher is with typewritten work! RUNNING SCHEME See the file /home/cs227/doc/running-scheme.txt for details about running Scheme. 17. (10 points; basic) In this problem you will edit and run a simple scheme program. The questions below are for your own benefit; don't hand in answers. You will hand in a printout of the program when you are done. Create a file, let's call it ``roulette.ss'', using emacs. (You need to be in your home directory for this; do ``cd'' at the Vincent prompt to get to your home directory.) In the file place the following Scheme procedure definition. (define roulette-wheel (lambda () (random 37))) Now start up scheme. In the scheme interpreter you can play with expressions. For example, if you type (random 37) or (random 100) something happens. Try calling (random 2) a few times. What numbers can it return? Now it's time to bring Las Vegas to Ames. Type in Scheme: (load "roulette.ss") to load in the code that you wrote in the file ``roulette.ss''. If you get an error, go back emacs, correct the file, and write it out again. Then do (load "roulette.ss") again. Now call the procedure roulette-wheel by typing (roulette-wheel) a few times. What happens? What happens if you leave off the parentheses? Now let's make this more useful. Go back to emacs (either by using the mouse on a workstation, or by using (exit) if you are not on a workstation), and change the file so that the roulette-wheel procedure looks like the following. (define roulette-wheel (lambda (bet-number) (compare-with-bet (random 37) bet-number))) This procedure calls the procedure compare-with-bet to compare the bet to the random number. But we still have to write that. The following should work. (define compare-with-bet (lambda (wheel-spin bet) (begin (if (= wheel-spin bet) (writeln "You won!") (writeln "You lose!")) wheel-spin))) Now write out the file and get back into Scheme. Load the file as before, by typing (load "roulette.ss") and then place you bet... for example, try (roulette-wheel 4) (If you get a message like ``Error: variable writeln is not bound.'' it means you did problem 7 incorrectly. Go back to problem 7. If you get other error messages, you made a typing mistake, check your input file and what you typed just now again.) What happens if you call roulette-wheel with no arguments now? What if you pass it a string, such as "roulette.ss", instead of a number. What if you pass it two numbers? Note that you can also call compare-with-bet directly. (compare-with-bet 10 20) (compare-with-bet 27 27) This is useful in testing and debugging larger programs, which typically consist of many procedures. Hand in a printout of your file ``roulette.ss''. 18. (10 points; basic) In this problem you will make a transcript and see what a more complex Scheme program can do. Start Scheme and execute the following. (transcript-on "whoson.out") (load "/home/cs227/lib/whos-on-first.ss") then follow the instructions and play with the program. (You might want to look at the code in "/home/cs227/lib/whos-on-first.ss" particularly the *strong-cues* and *weak-cues* to try to make your dialogue more fun. But this isn't necessary.) When you are done, exit scheme and print out the file "whoson.out". Hand this in. 19. (5 points; extra credit only) Is the whos-on-first program of problem 18 intelligent? Discuss the reasons why you think it is or is not. Can a computer program be intelligent? 20. (10 points; extra credit only) Look at the code in "/home/cs227/lib/whos-on-first.ss". Currently there is no name for the right fielder. Make up a suitable name for the right fielder, and by mimicking the other data in *strong-cues* and *weak-cues*, add some additional responses to the program to discuss the right fielder. You'll have to copy the file to your directory first, and then edit it. Hand in a transcript of a session with your revised program, and a printout of your revised program, with your changes highlighted.