Skip to main content

CSC 151.01, Class 42: Higher-Order Procedures, Revisited

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Reading overview
  • Lab

News / Etc.

  • New partners! (You’ll keep your partner tomorrow, too.)
  • Welcome to ZG, our guest mentor.

Upcoming Work

  • Lab writeup: TBD.
  • No reading for Wednesday.
  • Exam 3
    • Exam due TONIGHT
    • Epilogue due tomorrow night (earlier is better)
  • Project Proposals due next Monday evening (artworks Tuesday).

Extra credit (Academic/Artistic)

  • Paul Bendich ‘01 talk on Data Science, Today, 11:00 a.m., Science 2021
  • Any of the Research, Scholarship, and Creative Activity Symposium events April 17-20. (2 ec max.)
  • Quince Contemporary Vocal Ensemble. 7:30 p.m., Wednesday, April 19, Sebring-Lewis.
  • #robinhoodfail: The Ethics of Public Scholarship and the Digital Liberal Arts, Thursday, 7:30 pm, JRC 101.

Extra credit (Peer)

  • Any of the Research, Scholarship, and Creative Activity Symposium events that involve your classmates, April 17-20. (No double dipping!)
  • Art House Arts Fest on April 22nd.

Extra credit (Misc)

None right now.

Other good things to do

  • If you participate in Thursday’s festivities, be moderate.
  • Dag Field Day, Saturday, April 29, noon-5pm, in the Club Athletic Field.

Questions

Can we use a non-recursive helper for closest-to-zero-a?
Yes.
I know that you told us not to use min, but I can’t figure out how to write closest-to-zero-a without using min. What should I do?
Figure out how you’d write the two-parameter min if it did not exist. Then adapt that to the problem at hand.
I’ve forgotten. How do I get DrRacket to reindent my code correctly?
Make sure that you have line breaks at appropriate places and then hit Ctrl-i.
Do you think it’s a good idea for me to hit Ctrl-i before submitting
my exam?
I don’t know. Do you want full credit?
Is it academically dishonest to hit Ctrl-i for another student?
Yes.
Do you want us to document helpers?
Yes.
What is good formatting?
All the parameters to a procedure are either (a) on the same line, (b) on individual lines, or (c) group logically on lines.
Newline after (lambda (params), at least at the top level.
(image-select-rectangle! image REPLACE
                         left top
                         width height)
Do I have to document local helpers?
If it’s a kernel, probably not. Okay, not required.
Anything else, yes, with a sentence.
If we verify our preconditions, do we still include them in the preconditions?
Yes
;;; Parameters:
;;;   i, a positive integer [verified]
;;;
;;
(define fun 
  (lambda (i)
    (when (or (not (integer?) i) (<= i 0))
      (error "i must be a positive integer."))
    (let kernel ([val i])
      (when (> i 0)
        (display i)
        (newline)
        (kernel (- i 1))))))
Do you want us to put [verified] next to parameters and preconditions
that we verify?
I like to see [verified], but do not require it.
What should I do when DrRacket crashes and eats my exam?
Use the one you mailed to yourself ten minutes prior.
Seriously?
Yes.
On number 3, can we assume that the list contains only real numbers?
Yes.
Can we discuss husk and kernel?
Quickly.
Husk protects the kernel. It has a series of checks to make sure that the parameters are of the correct form.
The kernel does the work.

Three minutes with your partner: What are the key ideas in this reading? (I will ask for answers.)

  • Broadly, we look for programming strategies that let us avoid writing repetitious code. DRY. Don’t repeat yourself!
  • We can generalize procedures, such as recursive color transforms.
    • We can make a template for what we’re supposed to do and fill in the template. (We try to show you templates for many recursive strategies. You wrote one for folding.)
    • You can make a procedure a parameter, so that your template actually does all the work. For example, vmap on the exam.
    • It turns out that we can write map if we want to.
  • We have this magic apply procedure. Takes a procedure and a list and applies the procedure to the entire list, rather than one-by-one as in map.
> (map list (iota 4))
'((0) (1) (2) (3))
> (apply list (iota 4))
; Equiv to (list 0 1 2 3)
'(0 1 2 3)
> (list (iota 4))
'((0 1 2 3))
  • You could write your own section!
;;; Procedure:
;;;   left-section
;;; Parameters:
;;;   proc, a binary procedure
;;;   left, a value
;;; Purpose:
;;;   Fill in one parameter of proc.
;;; Produces:
;;;   newproc, a unary procedure
(define left-section
  ; The procedure we're defining
  (lambda (proc left)
    ; The procedure we're returning
    (lambda (right)
      (proc left right))))

Important! You can create new procedures by using lambda!

Lab

Writeup

  • 2b. There is no wrong answer; this is a case of preferences.
  • Try to get the writeup done before tomorrow’s class.
  • You will have the same partners tomorrow!

Writeup

Write up exercise 2b from the lab on higher-order procedures.

Send your solution to csc151-01-grader@grinnell.edu.

Title your email CSC 151.01 Writeup for Class 42 (YOUR FULL NAMES).