This assignment gives you your first chance this semester to write your own expressions and use a Racket interpreter to evaluate them. As mentioned in the syllabus and elsewhere, Dr. Racket is our default environment for the course. You may use the command-line interpreter, if you prefer.
Learning a new programming language involves learning its tools. Being an interactive language, Racket's tools may feel different than the programming tools that you are used to using. Be sure to devote sufficient time and energy to familiarizing yourself with Dr. Racket, its editor, its help system, and the like. Time invested now will pay big dividends later on!
As we go through the course, you will occasionally run across a question of the form, "I wonder how I do <x> in Dr. Racket?" In order to support your quest for timely answers, I maintain a page of helpful hints for using Dr. Racket. If someone asks a question that seems to have some long-term use to us, I will add the question and answer to the page.
Open Dr. Racket. Hide the Definitions pane, using the option available on the View menu. Familiarize yourself with the Interactions pane by typing a few simple expressions, perhaps riffing the expressions we evaluated in Session 2. Any time you want to "clear" the interactions, hit the Run button at the top of the window.
Once you feel reasonably comfortable with Interactions pane, do the tasks below. For each task, you will...
When you are done, save the contents of your Interactions pane to a text file, using Save Interactions as Text... option that is available under Save Other on the File menu. You will submit this transcript as your homework assignment.
You may want to use the following Racket primitive functions:
You do not need any information about Racket's data types that isn't available on this page or in Session 2. After you finish the assignment, you are certainly free to explore Chapter 4 in the Racket language reference, to learn more about the many data types available in the language and the basic functions for operating on each of them.
Note: I am not asking you to write Racket functions -- only expressions. For example, if I ask you to write an expression to compute the value of 2 + 2, you would write the Racket expression (+ 2 2):
> (+ 2 2) 4 >
We will begin writing functions soon enough. Be patient!
Some New Racket. Exercises 5 through 8 deal with Racket lists. You all have experience with lists in Python. Here is a quick introduction to Racket lists. (We will learn more about lists next week.)
> (define my-list '(1 2 3 4)) > (first my-list) 1 > (rest my-list) '(2 3 4) > (first (rest my-list)) 2 > (rest (rest my-list)) '(3 4)
> (length my-list) 4 > (length (rest (rest my-list))) 2(What does length return if its argument is not a list?)
You are ready to begin!
(+ 39 (- 14 27)) (- 73 (* (- 3 11) -7)) (* 7 (/ 24/7 30)) (- (+ (- (* 10 98) (* 7 6)) (* 543 2)) 1)
4 * 6 - 7 + 11 (4 * 6) - (7 + 11) 1.6 + 1/3 * 6 - -1.7 1.6 + 1/3 * (6 - -1.7)For the unparenthesized expressions, use the precedence rules you know from Python or Java.
2x2 + 2x - 24 = 0Yes, you need to use the quadratic formula!
(define big-number 1059430001) (define small-number 0.002000015) (define msu 'spartans) (define number1 big-number) (define number2 'big-number) (define symbol1 msu) (define symbol2 'msu)
big-number small-number 'big-number msu 'msu number1 number2 'number1 symbol1 symbol2 'symbol2
'(a (b c) d)
'(5 4 (x) 2 1) '(1 (2 (3) 4 5) (6 x 8)) '(((1 ((2)) ((x (3)) 5))))
> (define x /your answer/) > (first (rest x)) '(a b) > (rest (first x)) '((c) d e) > (rest (rest x)) '(f (g) h)
Create a transcript of your interaction with Dr. Racket that demonstrates your expressions for each of the above exercises.
By the due date and time, submit the transcript of your interaction with Dr. Racket using the electronic submission system.
By the due date and time, email me at least one question that you have about Racket now that you've worked with it for a while. This is your chance to have me answer the questions that are slowing you down right now. Yes, this is required.