Functional Problem Solving (CSC 151 2014F) : EBoards

CSC151.01 2014F, Class 23: Revisiting Lists


Overview

Preliminaries

Admin

Upcoming Work

Cool Things Coming to Campus

Extra Credit Opportunities

Academic

Peer Support

Questions

Could you explain Problem 2 on Assignment 5?

Please explain Euclidean distance

Requires whiteboard. (Sam will try to transcribe.)

Lists, revisited

Is there a way to put an element at the end of a list?

No built-in one, but you can probably figure out some strategy.

    (append lst (list val))

    (reverse (cons val (reverse lst)))

How do you get the last element in a list?

    (list-ref lst (+ -1 (length lst)))

    (car (reverse lst))

Lab

How do we refer to the empty list?

Any of the following

    null
    '()
    (list)
    (make-list 0 "anything")

I prefer null.

Why do the indices start with 0 rather than 1?

Computer scientists like to start counting with 0.

It lets you think of (list-ref lst i) as "take the cdr i times, then take the car"

What would lead you to name three lists one-two, won-too, and want-to?

Lack of sleep.

Congratulations, you are the last class that will ever have to deal with these stupid names.

Why did we have that exercise?

To reinforce that "if you ssee a period, it's not a list"

What do you think of the following code to find element 5 using cdr and car?

    ((o car cdr cdr cdr cdr cdr) letters)

Creative.

What do you think of the following for rectangularize?

    (define rectangularize 
      (lambda (drawing)
        (list 'drawing 'rectangle
              (list-ref drawing 2)
              (list-ref drawing 3)
              (list-ref drawing 4)
              (list-ref drawing 5)
              (list-ref drawing 6)
              (list-ref drawing 7))))

My, that's a lot of work.