Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Class 37: Trees


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support (Morning Section)

Miscellaneous

Nothing at present

Other Good Things (no extra credit)

Questions

Debrief from yesterday

What should we take from yesterday's lab?

Why are we studying this?

How Scheme prints lists

We see our first pair Print a single quotation mark and an open paren Print the car Look at the remaining pairs Print a space Print the car When you hit null, print a close paren When you hit something other than null, print the profanity symbol (.) and the cdr

(define print-something (lambda (thing) (cond [(pair? thing) (display "'(") (print-something (car thing)) (let kernel ([remaining (cdr thing)]) (cond [(null? remaining) (display ")")] [(pair? remaining) (display " ") (print-something (car remaining)) (kernel (cdr remaining)]

Writing listp?

A list is a collection of values.

In Scheme, we can build lists with pair structures.

"A list is either null or (cons VALUE LIST)".

 (define listp?
   (lambda (val)
     (or ; is it null?
         (null? val) 
         ; is it a pair whose cdr is a list
         (and (pair? val) 
              (listp? (cdr val))))))

"Structural recursion" -> Recurse over the parts of a structure (e.g., built with pairs)

Lab

Writeup is cancelled.