Functional Problem Solving (CSC 151 2013F) : Outlines

Outline 44: Higher-Order Procedures, Revisited


Held: Wednesday, 20 November 2013

Back to Outline 43 - Association Lists. On to Outline 45 - Binary Search.

Summary

We revisit the topic of higher-order procedures, one of the most important techniques in languages like Scheme. Higher-order procedures are procedures -- like map, left-section, or compose -- that take other procedures as parameters, return other procedures as values, or both.

Related Pages

Overview

Administrivia

Background: Guiding Principles

Background: The Value of Repetition

Procedures as First-Class Values

(define apply-to-2-and-3
  (lambda (proc)
    (proc 2 3)))
(define adder
  (lambda (n)
    (lambda (x)
      (+ x n))))
(define inc (adder 1))

Old Notes

The following are notes I wrote for past versions of the course. I probably won't discuss any/all in class.

Two Motivating Examples

Procedures as Parameters

Procedures as Return Values

(define redder
  (lambda (amt)
    (lambda (color)
      (rgb ...))))
(define left-section
  (lambda (func left)
    (lambda (right)
      (func left right))))
(define l-s left-section)
(define right-section
  (lambda (func right)
    (lambda (left)
      (func left right))))
(define r-s right-section)

Encapsulating Control

(define map
  (lamda (fun lst)
     (if (null? lst)
         null
         (cons (fun (car lst))
               (map fun (cdr lst))))))
(define all-numbers?
  (lambda (lst)
    (or (null? lst)
        (and (pair? lst)
             (number? (car lst))
             (all-numbers? (cdr lst))))))
(define all-symbols?
  (lambda (lst)
    (or (null? lst)
        (and (pair? lst)
             (symbol? (car lst))
             (all-symbols? (cdr lst))))))
(define all
  (lambda (test? lst)
    (or (null? lst)
        (and (pair? lst)
             (test? (car lst))
             (all test? (cdr lst))))))

Concluding Comments


Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-2013 Janet Davis, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials are copyright by John David Stone or Henry Walker and are used with permission.)

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.