Functional Problem Solving (CSC 151 2016S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [Remote] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2016S)] [Davis (2013F)] [Rebelsky (2015F)] [Weinman (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
sectionlambdaImportant lesson: If you want to watch what a procedure does, you can
make an alternate version of the procedure that calls display and
yield with a call to the underlying procedure.
(define square
(lambda (x)
(* x x)))
(define square_*
(lambda (x)
(display "squaring ")
(display x)
(yield (square x))))
You can then substitute the verbose version so that you know when your procedure is called (and what it does). Many programmers find this a really helpful approach.
In DrRacket, you'll see the display output and the returned value in
different colors. (You can use the computed value; you can't really
use the displayed stuff.)
Since computers and humans deal with values differently, sometimes we
want custom versions of yield.
Writeup: Exercise 4