Discuss the homework problems :
(f x . y)
notationAnd let's do 2.23 in class ... which I meant to assign. ;)
Implement for-each which loops over a list :
(for-each
(λ (x) (newline) (display x))
(list 57 321 88))
Here's my answer .
This week I'd like to continue on in chapter 2, looking at the material related to trees and traversing through trees. Some of this should be familiar to those of you who have seen some data structures already.
I've posted the next set of homework problems. This material continues the fold-left and fold-right ideas that I presented last time, as well as a looking at trees.
To get a start on that stuff, let's go over the material in 2.2.2 : "hierarchical structures" :
Figure 2.5 :
(cons (list 1 2) (list 3 4))
[ / \ ]
/ \
/ \
[1 2 [3 4]
Figure 2.6
'((1 2) 3 4)
1234----
/ \ \
12 3 4
/ \
1 2
Scheme has a built-in pair?
predicate, which
we can use to see if we've reached the end points
("leaves") of a tree.
> (pair? 1)
#f
> (pair? (cons 1 2))
#t
The book defines a (count-leaves tree)
procedure
to see how many terminal nodes there are in a tree.
Can we work that out ourselves?
... we'll work through exercise 2.42 in class, the classic eight queens puzzle ;)