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.
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. Any time 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 from Session 1. 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, 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 procedures:
Feel free, if you'd like, to explore the chapter on Data in the Racket language reference, which talks about data types and describes basic procedures for operating on each. However, you won't need any information about them that isn't available on this page or in Session 2.
Note that I am not asking you to write Racket functions -- only simple expressions. For example, if I ask you to write an expression to compute the value of 2 + 2, you would write the Scheme 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!
(* (- 34 27) 11) (- 12 (- (- 7 11) 3)) (/ 42 (* 24 5)) (+ (* 0.01 20) (/ 4 -3))
3 * 9 - 12 + 8 (3 * 9) - (12 + 8) 1.6 + 6 * 1/3 - -1.7 1.6 + 6 * (1/3 - -1.7)
6x2 + 5x - 4 = 0
Yes, you need to use the quadratic formula!
(define big-number 1059034001) (define small-number 0.000002005) (define ball-state 'cardinals) (define number1 big-number) (define number2 'big-number) (define symbol1 ball-state) (define symbol2 'ball-state)
... what is the value of each of these expressions?
big-number small-number 'big-number ball-state 'ball-state number1 number2 'number1 symbol1 symbol2 'symbol2
(a b (c d))
(5 4 (x) 2 1) (1 (2 (3) x 5) (6 7 8)) (((1 ((x)) ((3 4) 5))))
> (define x /your answer/) > (first (rest x)) 'a > (rest (first x)) '((b c) d e) > (rest (rest x)) '(f g)
By the due date and time:
Be sure that your submission follows all homework submission requirements. Your file is not a Racket program, so it does not need to have a header block or be loadable by Dr. Racket. (See the requirements page for more about these.)