Functional Problem Solving (CSC 151 2014F) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Held: Monday, 17 November 2014
Back to Outline 41 - Randomized (Unpredictable) Drawing. On to Outline 43 - Analyzing Procedures.
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
(image-redo! image (lambda (x y color) newcolor)) is the generalization
of image-transform! and image-compute.The following is variant of something my colleague John Stone says ...
You learn from reading.
You learn from writing.
So ... extract the common code so you don't have to write it again.
map) that take other procedures
as parameters.left-section and compose) that
return other procedures.
(define apply-to-2-and-3
(lambda (proc)
(proc 2 3)))
(define adder
(lambda (n)
(lambda (x)
(+ x n))))
(define inc (adder 1))
The following are notes I wrote for past versions of the course. I probably won't discuss any/all in class.
all-real? and all-integer?add-5-to-each and multiply-each-by-5
(define redder
(lambda (amt)
(lambda (color)
(rgb ...))))
compose
<>boxcode
(define compose
(lambda (f g)
(lambda (x)
(f (g x)))))
(compose sin sqrt)(compose car reverse)left-section
(define left-section
(lambda (func left)
(lambda (right)
(func left right))))
(define l-s left-section)
(l-s + 2)(l-s * 2)
(define right-section
(lambda (func right)
(lambda (left)
(func left right))))
(define r-s right-section)
map is the standard example.
(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))))))