Due by class time Thursday, September 5
Read all of the information on the course web page, paying particular attention to my policies for the semester.
Our course is based on the core ideas of the book Essentials of Programming Languages by Friedman and Wand. However, we aren't using it as a textbook this semester, because it is a little too technical for our purposes. Nevertheless, the Forward by Professor Hal Abelson of MIT gives an excellent overview of why interpreters are important in computer science, and why this material is worth studying. Read the Forward to the book, substituting the word "course" in place of the word "book" in your mind as you read.
Read Chapter 1 of The Little Schemer, 4th Edition. Read each question carefully and slowly, pausing to think about your answer before going on to the next question. If you don't yet have a copy of the book, it is available in the SLC Library on 3-hour reserve. As a temporary measure, a PDF of Chapter 1 is also available on our MySLC class page under Handouts. (You'll need to log into MySLC first.)
Work through my interactive Jupyter notebook A Quick Introduction to Scheme. To execute a code cell, simply click anywhere inside the cell and then press Shift-Return.
Download, install, and configure DrRacket on your computer. You'll only need to do this once.
Start DrRacket and create a new blank Scheme file named assign1.scm, as follows: choose File → Save Definitions As... and type assign1.scm (always make sure to include the .scm extension in your filenames!), then click Save. Your Scheme definitions will go in the upper window. To load your code into Scheme for testing, just click the Run button in the top right corner. Try this out by typing the definition
(define pi 3.14159)in the upper window, then clicking Run and typing pi at the Scheme prompt in the lower window. It should return 3.14159.
Write and test the function (sphere-volume radius), which takes a radius value as input and calculates the corresponding volume of a sphere using the symbol pi and the formula below:
Examples:
(sphere-volume 1) → 4.188786666666666 (sphere-volume 3) → 113.09723999999999 (sphere-volume 0) → 0
Write and test the function (absolute-value n), which takes a number n as input and returns its absolute value. You are not allowed to use Scheme's built-in abs function for this problem. Instead, use cond to check if n is less than 0. Examples:
(absolute-value -3) → 3 (absolute-value 3) → 3 (absolute-value 0) → 0
Write and test the function (distance x1 y1 x2 y2), which takes four numbers as input, in the order shown, representing the coordinates of two points (x1, y1) and (x2, y2), and computes the distance between the points using the formula below. Hint: The square root function in Scheme is called sqrt.
Test your function thoroughly. Examples:
(distance 1 2 4 6) → 5 (distance 1 1 2 2) → 1.4142135623730951 (distance 4 0 -6 3) → 10.44030650891055
Write and test the function (replace-first new ls), which takes a symbol new and a list of symbols ls as input, and returns a new version of ls with the first symbol replaced by new. If ls is empty to begin with, an empty list is returned as the result. Examples:
(replace-first 'apple '()) → () (replace-first 'apple '(chocolate sauce yum)) → (apple sauce yum) (replace-first 'blue '(green eggs and ham)) → (blue eggs and ham) (replace-first 'nobody '(Sam loves green eggs and ham)) → (nobody loves green eggs and ham) (replace-first 'margarine '(butter)) → (margarine)
Save your Scheme definitions from Exercises 1-4 in a file named assign1.scm. Make sure to include your name and the assignment number in a comment at the top of your file. The comment symbol in Scheme is the semicolon. A comment begins with ; and continues to the end of the line.
Please DO NOT email your file to me. In class on Thursday, I will show you how to submit your file electronically using the Homework Upload Site.
If you have questions about anything, please don't hesitate to ask!