Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.02 2015S, Class 25: Recursion Basics, Continued


Overview

Preliminaries

Admin

I did not take time last week to condemn the postings on Yik Yak because I thought the president's statement sufficed. But it sounds like individual voices are necessary, too. And, as a technologist, I have particular responsibility to comment in this case. So I should have done so more promptly. I apologize for the delay, particularly because this issue is very important to me.

Let me make it absolutely clear. Use of any medium - social, physical, virtual - to denigrate other people for their characteristics is completely unacceptable. I have updated our course front door to clarify this perspective. (If you have comments on how to better phrase my policy, I would appreciate them.)

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support (Afternoon Section)

Miscellaneous (Extra Credit)

Other Good Things (No Extra Credit)

Questions

How should we ask whether a list has one element?

(null? (cdr lst))

Do not use (= 1 (length lst))!

When will we get the quizzes back?

Wednesday, I hope. Otherwise Monday.

Lab

One of the mentors wants to see you write riffle, which is the last problem in the extras session.

I don't care what value you give for (product null), so choose whatever is most helpful for you.

There are at least six different correct answers I've seen for irgb-tally-darks.

Debrief

Two approaches to product

(define product
  (lambda (lst)
    (if (null? lst)
        1
        (* (car lst) (product (cdr lst))))))

(define product
  (lambda (lst)
    (if (null? (cdr lst))
        (car lst)
        (* (car lst) (product (cdr lst))))))

Two ways to code riffle

(define riffle
  (lambda (first second)
    (cond
      [(null? first) second]
      [(null? second) first]
      [else (cons (car first) 
                  (cons (car second) 
                        (riffle (cdr first) (cdr second))))])))

(define riffle
  (lambda (first second)
    (if (null? first)
        second
        (cons (car first) 
              (riffle second (cdr first))))))