Due by class time Friday, September 10
Read all of the information on the class web page, paying particular attention to my course 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 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" as you read.
Download, install, and configure DrRacket on your computer. You'll only need to do this once.
Read Chapters 1 and 2 of The Little Schemer, 4th Edition. Do not rush through these chapters. Instead, 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 Chapters 1 and 2 is also available on our MySLC class page under Handouts.
Work through the interactive Jupyter notebook A Quick Introduction to Scheme. To execute a code cell, simply click anywhere inside the cell and press Shift-Return.
Work through these list-manipulation exercises and write out your answers on paper. You may use DrRacket to check your answers, but only after you have first thought about each question carefully, and have attempted to answer it on your own. Make sure you understand the results that DrRacket gives for each expression.
Define the symbol pi to be the value 3.14159 by including the following definition in your code:
(define pi 3.14159)
Then 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. The distance is given by the formula:
Make sure to 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 Friday, 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!