Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Class 11: Side Effects: Output and Input


Overview

Preliminaries

Admin

Reminders

Upcoming Work:

Exam 1

Extra Credit

Academic

Peer

Regular Peer

No Extra Credit, But Still Good

Questions

Lab!

Important 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