EBoard 20: Recursion lab

Warning! You are being recorded (and transcribed) (provided the technology is working correctly).

Approximate overview

  • Administrative stuff [10 min]
  • Finishing up the sorting exercise [10 min]
  • About MP5 [10 min]
  • Questions [5 min]
  • Lab [40 min]
  • Turn in Lab [5 min]

Administrative stuff

  • Advance warning: We “spring ahead” on Sunday morning.
  • Mid-semester reports were due last night. While I have confidence that every one of you can earn an A this semester, I needed to turn in a few reports for people who seem to be having particular struggles. Please make an appointment to chat with me.

Token opportunities

Academic/Scholarly

  • Thursday, 2024-03-07, 11:00 a.m.,JRC 101. Scholars’ Convocation: An American Genocide: The United States and the California Indian Catastrophe, 1846-1873
  • Thursday, 2024-03-07, 7:00pm, Science 3819. Mentor Session (on recursion).
  • Tuesday, 2024-03-12, noon, Some PDR. CS Table.
  • Tuesday, 2024-03-12, 7:00pm, Science 3819. Mentor Session (on the topic of the prior mentor session)

Cultural

  • Thursday, 2024-03-07, JRC 101, 8:00-9:30 pm. Writers@Grinnell: Carl Phillips
  • Thursday–Saturday, 2024-03-07 to 2024-03-09, 7:30 p.m. Songs of the Scarlet and Wayback (play).
  • Friday, 2024-03-08, 4pm, Global Living Room in HSSC. Middle of Everywhere.
  • Saturday, 2024-03-09, Harris Cinema, ??:?? Met Opera: Verdi’s La Forza del Destino.
  • Saturday, 2024-03-09, 2:00 pm, Sebring-Lewis. ZAWA! (Flute concert).

Peer

  • Saturday, 2024-03-09, Field House. Men’s and Women’s Tennis vs. Central.
  • Sunday, 2024-03-10, 1–3pm, in JRC 225. Fiber Arts Club. Community. Arts. Music in the background. What could be better.

Wellness

  • Wednesday, 2024-03-06, 4pm, JRC 101. Intimacy Stages.
  • Friday, 2024-03-08, noon, JRC 101. Wellness Bingo.
  • Tuesday, 2024-03-12, noon-1pm, BRAC P103. HIIT and Strength Fitness Class.
  • Tuesday, 2024-03-12, 12:15–12:50, Bucksbaum 131. Yoga in the Museum.
  • Tuesday, 2024-03-12, 4pm, BRAC P103 (Multipurpose Dance Studio): Yoga.

Misc

Other good things (no tokens)

Upcoming work

About MP5

  • A bit behind in writing.
  • Described in class.
  • Should be ready by 2:30 p.m. today.
  • (Images coming tomorrow.)

Wrapping up the sorting example

;;; (insert-number num sorted-nums) -> (list-of integer?)
;;;   num : integer?
;;;   sorted-nums : (all-of list-of-integer? sorted?)
;;; Insert `num` into the correct place in `sorted-nums`
;;;
;;; Notes: Look at each element in turn. If you're bigger, skip over
;;; it. If you're smaller, insert it there. If there are no elements,
;;; inserting it means "create a new list".
(define insert-number
  (lambda (num sorted-nums)
    (cond
      [(null? sorted-nums)
       (list num)]
      [(<= num (car sorted-nums))
       (cons num sorted-nums)]
      [else
       (cons (car sorted-nums)
             (insert-number num (cdr sorted-nums)))])))

TPS: In your own words, explain what insert-number is doing.

Try tracing it by hand.

;;; (sort-nums nums) -> (all-of (list-of integer?)  sorted?)
;;;   nums : (list-of integer?)
;;; Sort `nums` in increasing order.
(define sort-nums
  (lambda (nums)
    (if (null? nums)
        null
        (insert-number (car nums)
                       (sort-nums (cdr nums))))))

TPS: In your own words, explain what sort-nums is doing.

Remember: Think inside-out.

Questions

Administrative

For SoLA 2, have you posted the grades for the list quiz?

I think so.

Recursion

Lab

Please finish the lab before Friday’s class, either on your own or with your partner.