CS61A Summer 2011 Lab 1A
Try to get as much done as possible, but don’t panic if you don’t finish everything.
- Start the Emacs editor, either by typing emacs & in your main window or by selecting it from the alt-middle mouse menu. (Your TA will show you how to do this.)
- Start Scheme, either by typing stk in your main window (okay option) or by typing meta-s in your Emacs window (BEST OPTION - note “meta” is the diamond key or “Esc” on PCs). Type each of the following expressions into Scheme, ending the line with the Enter (carriage return) key. Think about the results! Try to understand how Scheme interprets what you type.
(+ 2 3)
(+ 5 6 7 8)
(first (bf ‘hello))
(+ (first 23) (last 45))
(define pi 3.14159)
(+ (* 3 4) 5)
(+ pi 7)
(* pi pi)
‘(+ 2 3)
(define (square x) (* x x))
(square (+ 2 3))
- Use Emacs to create a file called pigl.scm in your directory. It will contain the Pig Latin program shown below. Note that you can create a new file using the File menu in Emacs, although it won’t pop up a dialog box like you might expect! Instead, your cursor will jump to the bottom of your Emacs window. Once it’s there, type pigl.scm and hit enter to create your file.
Make sure you are editing a file whose name ends in .scm, so that Emacs will know to indent your code correctly! Also, note the first two lines begin with a semicolon; Scheme will ignore everything that comes after a semicolon until the end of the line, so it’s a good way to write comments about your code. In this case, we’re using comments to include your name and TA in the file. You should do this in every file you make for this course!
Also, don’t copy and paste the following code directly. Retype it! Copying and pasting can introduce weird extra characters or unusual quotes, and they tend to confuse Scheme. (Poor Scheme!)
; put your name here
; put your TA name here
(define (pigl wd)
(if (pl-done? wd)
(word wd ‘ay)
(pigl (word (bf wd) (first wd)))))
(define (pl-done? wd)
(vowel? (first wd)))
(define (vowel? letter)
(member? letter ‘(a e i o u)))
- Now run Scheme. You are going to create a transcript of a session using the file you just created. A transcript essentially records the commands you type into the interpreter and puts them in a file. You will use this feature often to show us that you’ve tested your projects properly!
(transcript-on “lab1”) ; This starts the transcript file, and will
; name the file “lab1”. Don’t say
; (transcript-on “pigl.scm”), or else you’ll
; overwrite your program!
(load “pigl.scm”) ; This loads the file you created into STk.
(pigl ‘scheme) ; Try out your program!
; Try out some other words, too.
(trace pigl) ; This is a debugging tool. Watch what
; happens when you run a traced procedure.
(transcript-off) ; This stops the transcript file.
- Use the lpr command to print your transcript file. To do this, type the following command into your main xterm window (not Emacs or Scheme):
This will print the lab1 file in the room opposite from 273 Soda. You could print other files - say, pigl.scm - by issuing a similar command:
- Switch back to Emacs, and from the Help menu, select the Emacs tutorial. This is a valuable resource for learning to use Emacs, but it could take you years to complete! Check it out, but by no means feel obligated to finish it.
Congratulations on finishing your first lab!