Assignment - Scheme Warmup

Due in Lecture Feb 10. Except for the Parameter Passing question (question 4), these Scheme functions must all be written in a pure functional style (no side effects).

To turn in your work, please put all of your functions, using the names specified in the homework, in a single file called 'homework4.scm'. Make a separate text file with the output of your tests with clear headings for the output from the different functions. Use the following turnin command to turn the file in electronically:

turnin homework4.scm homework4-output.txt
Do not zip or tar the files before turning them in. To check that the turnin was successful, use turnin -v

See the 341 homework submission guidelines for general information, and for tips about how to capture the output from Scheme to turn in.


  1. Write and test a Scheme function to find the area of a circle, given its radius. For example, (area 2.0) should return the area of a circle of radius 2.
  2. Write and test a recursive Scheme function that takes a list of numbers, and returns a new list of the squares of those numbers. For example, (squares '(1.0 2.0 3.0)) should return (1.0 4.0 9.0).
  3. Write and test a Scheme function to test whether a list of numbers is in strict ascending order. For example, (ascending '(1 2 3)) should return true, while (ascending '(2 1)) and (ascending '(1 1)) should both return false. You don't need to check for inputs that aren't lists of numbers. However, you should handle the empty list, and a list of one number. (What should these return? Justify your decision in a comment in the code.)
  4. Three CSE 341 students are arguing about what parameter passing mechanism is used in Scheme. Samantha claims that it is pass by value with pointer semantics (as in Java), Ben claims that it is pure pass by value (in which the entire argument is copied), and Chris says that it is call by reference. Who is right? Unfortunately, none of these students is going to be convinced by just showing them what the lecture notes or the book says -- you have to prove to them that Scheme works one way or the other. Write some small test programs in Scheme that prove that parameters are passed the way you say they are. Explain in words why these test programs prove what you say.

    Hints: look at the lecture notes for examples in other languages that behave differently under different parameter passing mechanisms. You can assign into a function's parameter in Scheme (although it is very bad style - so only do this to prove your point here, and not anywhere else). For example:

    (define (test x)
      (display "x = ")
      (display x)
      (newline)
      (set! x '(elmer fudd))
      (display "after the set! x = ")
      (display x)
      (newline))
    
    If you want to use the eq? function in proving your point, use a list as the argument you're passing -- eq? applied to numbers may have unexpected behavior.

    Other functions that you could use to prove your point are set-car! and set-cdr! that do list surgery. (These are even more evil than set!, so don't use them except for this question.) For example, try this code in an interactive session, and see what happens to x after each statement:

    (define x '(john paul george ringo))
    (set-car! x 'elvis)
    (set-cdr! x ())