This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
Attend (or watch recording within a day or so) and send a one-paragraph reflection asap afterwards.
Only those activities I list count.
language.rkt.None yet.
None yet.
None yet.
Will you release a set of sample problems?
Yes.
Will the mentors hold sessions?
Yes.
For the tail-recursion problem on SoLA 3, will we be transforming functions we are given?
Yes.
But I won’t give you a template.
Do you really believe that we’ll know enough about dictionaries to do a problem on them?
I hope that after the lab, you will be able to do a problem on dictionaries.
Thank you for the hint about keeping the problem reasonable.
Could you go over the weirdo variants?
(cadr x)is(car (cdr x))(element 1 of the list)
(caddr x)is(car (cdr (cdr x)))(element 2 of the list)
(cadar x)is(car (cdr (car x)))(element 1 of the element 0 of the list) [we’re dealing with a list of lists]
(caddddddr x)might be(car (cdr (cdr (cdr (cdr (cdr (cdr x)))))))(element 6?)
(caaaar x)might be element 0 of element 0 of element 0 of element 0 of an incredibly nested list.
What about vectors makes them different than lists?
In the reading on pairs, you saw that lists are structured like this in memory (e.g., ‘(a b c))
+-+-+ +-+-+ +-+-+
| |*--> | |*-> | |/|
+|+-+ +|+-+ +|+-+
| | |
v v v
a b c
Morals: We have to follow all of the arrows which (a) might make our head hurt and (b) takes some time.
Here’s what the same vector looks like
+-+-+-+
|*|*|*|
+|+|+|+
| | |
v v v
a b c
Important: Just one chunk of memory.
Important: It’s easy to calculate where the reference to the element i is: Start of the vector in memory + i*width-of-a-cell.
Only takes a short calculation to find the ith element, rather than a long one.
Why aren’t lists arranged like vectors?
Adding an element to the front of the list is fast.
Adding an element to a vector requires copying the whole vector.
As an algorithm designer or programmer, you think about which is best for the current situation.
Why doesn’t vector-set! work with vectors defined with '#(x1 x2).
The designers of Racket decided that those would be “constant vectors”, vectors that are immutable. It avoids accidental changes.
Lists are also immutable. You can make new lists from old, but you can’t change an existing list.
mapandfiltermake new lists.
How do you get Racket to display a vector you’ve changed with vector-set!?
We type the vector’s name again.
> (define vec (vector "a" "b" "c"))
> vec
'#("a" "b" "c")
> (vector-set! vec 2 "x")
> vec
'#("a" "b" "x")
If we are not happy with our MP redo grade, can we redo again?
Sure. Our graders love grading.
I’ll figure out how to manage that.