Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Class 37: Trees


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support (Afternoon 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

Print
  If you have a pair
    print a single quotation mark
    print an open parentheis
    print the car
    move on to the cdr
    ^ if the cdr is null
    |   print a close paren and stop
    | if the cdr is a pair
    |   print a space
    |   print the car
    +---+ loop back and do it all over again
    | otherwise
    |   print a space
    |   print a curse
    |   print a space
    |   print the cdr
    |   print a right paren

Writing listp?

Write a procedure, (listp? val) that returns #t if val is a list and

f otherwise.

Reminder: A list is null or (cons VAL LIST)

    (define listp?
      (lambda (val)
        (or (null? val)
            (and (pair? val)
                 (listp? (cdr val))))))

Drawing trees vs. drawing lists

Lab