CS374: Programming Language Principles - Functional Programming with Scheme

Activity Goals

The goals of this activity are:
  1. To explore the functional programming paradigm using Scheme

Supplemental Reading

Feel free to visit these resources for supplemental background reading material.

The Activity

Directions

Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Declarative Languages - Functional




Questions

  1. What is a statement in Scheme?
  2. What shared variables exist in this program?
  3. What are some potential advantages of Functional Programming as a paradigm?
  4. How might you improve upon the implementation of the largest function?

Model 2: The Scheme Programming Language





Questions

  1. How are function parameters handled in Scheme? Are they passed by value or by reference?
  2. What is a function in Scheme? How is it represented?
  3. What does czr do in your own words?
  4. Write a function to count the number of items in a list using a recursive call and a base case, using czr as a guide to traversing a list.
  5. Diagram the binding of the values in the call to plusminus to the anonymous lambda function.
  6. What is the result of the map/apply sequence? What would happen if map were applied to only a single list?
  7. In your own words, define tail recursion. Do you see instances of tail recursion in these examples? Draw a call stack for one of these examples.
  8. Compare and constrast closures and objects.
  9. Using the pair? directive, which returns #t if the parameter is a nonempty list, add a check to one of these list recursion examples to ensure that null is returned if an empty list is passed.
  10. Write a function that accepts a list and an operator as parameters, such as addition. Apply that operator to the whole list recursively; for example, if the operator is the addition operator, return the sum of the list. If it is the multiplication operator, return the product of all items in the list.

Submission

I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.