# Class 18: More Higher-Order Procedures

Back to Higher-Order Procedures. On to Algorithm Analysis.

Held: Tuesday, 18 February 2003

Summary: Today we continue our investigations into higher-order procedures by grounding our discussion in further hands-on activities.

Related Pages:

Assignments:

• Review sections from Bailey.

Notes:

• A few of you asked about the six P's. Your Produces section should give a name and a type to the value returned by our procedure. Your Postconditions should define that return value (and any other effects) as specifically and formally as possible.
• Are there any other questions on exam 1?
• Are there any comments on Mr. Stone's book?
• To make the <Delete> key work the way you expect, uncheck Edit->Preferences->Editing->General->Map delete to backspace (thanks Arjun).
• You should have grades from homework 1. I don't plan to grade writeup 2.

Overview:

• Operator sections.
• Currying.
• Lab.

## Operator Sections

• One thing programmers regularly observe is that they want to create new procedures by filling in one argument of another procedure.
• Procedures that build new procedures by filling in individual arguments are called operator sections.
• The simplest such procedure is `left-section`
```(define left-section
(lambda (binproc left-param)
(lambda (right-param)
(binproc left-param right-param))))
```

## Currying

• Another interesting modification to procedures is to think about multi-arity procedures as procedures that return procedures that expect one few parameters.
• Consider the two-parameter `sum`. We might define it as
```(define sum
(lambda (val1)
(lambda (val2)
(+ val1 val2))))
```
• Similarly, we might think of our `filter` procedure as
```(define filter
(lambda (pred?)
(letrec ((recurrer
(lambda (lst)
(cond
((null? lst) null)
((pred? (car lst)) (recurrer (cdr lst)))
(else (cons (car lst) (recurrer (cdr lst))))))))
recurrer)))
```
• Now, we can make a filter for odd numbers as
```(define filter-odd (filter odd?))
```
• This technique is called Currying..

## History

Thursday, 15 January 2003 [Samuel A. Rebelsky]

• Created as a mostly-blank outline.

Monday, 17 February 2003 [Samuel A. Rebelsky]

• Filled in the details.

Back to Higher-Order Procedures. On to Algorithm Analysis.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue May 6 09:20:33 2003.
The source to the document was last modified on Mon Feb 17 19:52:29 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Outlines/outline.18.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu