Class 20: FP, Continued
Held Wednesday, March 10
- Kevin McLaughlin has installed a version of fp for your enjoyment.
It can be found in
- We'll stop during today's class and try the various examples.
- You may be wondering how to study for open-book take-home exams.
I'll admit that I don't think you need to do extensive studying
for such exams. Here are a few tips I use in studying for any
- Make a ``cheat sheet'', summarizing what you've learned.
- Make an ``index'' of important topics, and where to find more
information on those topics.
- Try to do some problems in the book or lab manual.
- Try to write some of your own problems, based on those you've
received in homework of I've mentioned in class.
- I've graded assignment 3.
- Late assignments have not been graded. I'll try to get them back
to you next week.
- An answer key is available.
I may be making some more changes to it later this week.
- A few of you worked together and didn't cite who you worked with.
This is a big no-no.
- A few of you worked together and turned in identical answers. You
are expected to write up your answers separately after discussing
- Assignment 4 is now
ready. You can do it for extra credit or in place of another
- Next week, we'll be discussing logic programming. You should probably
start reading chapter 11.
- A number of you had problems with the last problem on
- The problem was to add an ``assignment expression''.
- We'll refer to the
notes on assignment 3
for this discussion.
- FP also include functional forms: functions that take other
functions as arguments, or return functions as results.
- These are what some people seem to call higher-order functions.
- While some functional languages permit the user to define new functional
forms, FP limits you to a basic set.
- (Well ... officially, Backus is presenting a framework for languages,
so it's hard to say that it really limits you, but there does not seem
to be a language feature for defining new functional forms.)
- The basic functional forms are:
- Apply to all
- Binary to unary (think of this as applying a curried function to one
- Composition (the standard notion)
- Construction (turning a list of functions into a function)
- Condition (takes three functions as arguments)
- Constant (builds a function)
- Insert (a function between elements of a sequence)
- Apply to all (another name for map)
- While (perhaps the most confusing)
- Repeatedly apply a function to an argument until a predicate no longer
holds. (Pure: we use the result of the function in each recursive
(while p f):x == p:x = T -> (while p f):(f x) ;
p:x = F -> x; bottom
- The best way to understand FP is to apply it in some situations.
- We'll start with everybody's favorite recursive function, factorial.
- Instead of working with the definition in the paper, we'll try to
build it up ourselves.
- We'll build both recursive and iterative versions, to strengthen
our understanding of the language.
- Created Tuesday, January 19, 1999 as a blank outline.
- Filled in the details on Monday, March 8, 1999. Many details were
based on an outline of a class I taught long ago at Dartmouth, although
much was also rewritten.
- Added a few more notes on Tuesday, March 9, 1999.
- Removed uncovered material on Friday, March 12, 1999.