Functional Problem Solving (CSC 151 2013F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning] [Grading]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Setup] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2010F)] [Weinman (2012F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)]
Overview
Admin
Implementation is really straightforward
(define assoc
(lambda (key alst)
(cond
[(equal? key (caar alst))
(car alst)]
[else (assoc key (cdr alst))])))
Whoops? What if the list is empty? (That is, what if the element doesn't appear?) Early design decision: Return false.
(define assoc
(lambda (key alst)
(cond
[(null? alst)
#f]
[(equal? key (caar alst))
(car alst)]
[else (assoc key (cdr alst))])))
How do we use it?
Sample data
(define some-grinnell-courses
(list
(list "CSC151" "Hard" "Time-consuming" "Artistic" "Crash" "Mathy")
(list "TUT101" "Variable" "Necessary" "Writing-intensive")
(list "SPN105" "Time-consuming" "Talkative" "Memory-intensive")
(list "ANT1xx" "Mind-expanding" "Scientific")
(list "MUS1xx" "Interesting" "EZA")
(list "UM100" "Fictitious" "EZA" "Writing-intensive")))
(define lookup-courses-that-meet-paritular-criteria
(lambda (key alst)
(lookup-courses key alst)))
;;; Find a list of all courses that meet a particular criterion
;;; (that is, that include the word in the description list)
(define lookup-courses
(lambda (criterion courses)
(cond
[(null? courses)
null]
[(member? criterion (cdar courses))
(cons (car courses) (lookup-courses criterion (cdr courses))]
[else (lookup-course criterion (cdr courses))])))
(define member?
(lambda (val lst)
(and (not (null? lst))
(or (equal? val (car lst))
(member? val (cdr lst))))))
;;; Procedure:
;;; image-series
;;; Parameters:
;;; n, an integer
;;; width, a positive integer
;;; height, a positive integer
;;; Purpose:
;;; Create an "interesting" image.
;;; Produces:
;;; image, an image
;;; Preconditions:
;;; 0 <= n < 1000
;;; Postconditions:
;;; (image-width image) = width
;;; (image-height image) = height
;;; For all m != n
;;; (image-series m width height) is different than image
Yes, you should document each procedure you call. (Six P's are better, but even just a short purpose would be okay.)
;;; Make a "fence" that has the given number of slats
(define make-fence
(lambda (image number-of-slats)
....))
;;; Cut a hole in the fence at position (x,y)
(define holey-fence
(lambda (image x y)
...))
Folks who showed up today (YK, HF, WBC, ZC) and members of their groups do not need to make sure that turtle operations scale appropriately if the aspect ratio of the image changes. (However, they should scale appropriately if the aspect ratio stays the same and the image changes.)
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning] [Grading]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Setup] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2010F)] [Weinman (2012F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)]
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.)

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.