Structure and
Interpretation
of Computer
Programs

Fall 2021
course
site
-->

Sep 20

First: questions about anything?

Second: work through some examples together.

tree

;; Let's create a tree structure in scheme using (only) cons
;; ... and then access its pieces with (only) car and cdr
;; ... and then write some tools to do things to it.
;;
;; Here's a simple tree :
;;
;;          A
;;         / \
;;        B   C
;;           / \
;;          D   E
;;
;; To work with this we will
;;
;;   (a) pick a representation 
;;
;;   (b) define functions to create & access that representation (i.e. an API)
;;       ... and that particular tree, call it ABCDE
;;
;;   (c) define a function to count the number of nodes
;;       .. and apply it to ABCDE

We'll see if we can work through this together in class ... one solution is attached, which we can refer to later.

Notice particularly what we man by a "representation" and an "API" (i.e. functions to work with that representation to create and access it) ... the text discusses these notions in some length.

create & access vs modify

Notice that so far all of the operations we are looking at can build or examine these data structures ... but not (yet) modify them in place. And notice that even without "editing" capabilities, we can still do a lot.

length & append

We'll go over the append and length functions defined in the text, section 2.2.1 .

If the list(s) have length (n, m), what O() do these operations take?

There's a nice discussion in these recursion over data structures notes .

Let's try exercise 2.18 - reverse a list - as an exercise in class - first you think about and see what you can come up with on your own or working with someone else, then we'll discuss together.


The files we edited in class are attached.

https://cs.bennington.college /courses /fall2021 /sicp /notes /09-20
last modified Mon September 20 2021 4:58 pm

attachments [paper clip]

  last modified size
TXT length-copy-append.scm Mon Sep 20 2021 04:58 pm 1.0K
TXT tree-in-class.scm Mon Sep 20 2021 04:58 pm 800B
TXT tree.scm Mon Sep 20 2021 12:02 am 2.2K