CS153, Class 16: Vectors
Overview:
* Problems with lists.
* A solution: Vectors.
* Side note: The begin construct.
* Lab.
Notes:
* Happy valentine's day
* Are there questions on exam 1?
+ Q&A now in the exam.
+ Extended deadline.
* Read "Design Patterns and Higher-Order Procedures"
+ Sorry, it's somewhat long
* Read pp. 69-73 of Bailey.
* Cool math talk today at 4:30. Go and get extra credit.
a^p mod p = a for primes p
----------------------------------------
C++-ers:
Rewrite
(define exponent
(lambda (val power)
(cond
((zero? power) 1)
((even? power) (square (exponent val (/ power 2))))
(else (* val (exponent val (- power 1)))))))
in C++ without using recursion
Question: Does Scheme have iteration?
Answer: Yes: Named let is sort of like iteration. "do" is
Scheme's primary iteration mechanism.
Question: Does Scheme have pointers?
Answer: Yes. Pairs are pairs of pointers.
----------------------------------------
PReflection:
Why are lists cool?
* Defined recursively, so easy to recurse over
Do the lab
----------------------------------------
Reflection, Revisited
* When students don't show up, should I call them?
* Use quote to create vector literals
#(3.14159 #2.718) vs. '#(3.14159 2.718)
#(pi e) vs '#(pi e)
* Why use vector rather than #?
(vector pi e) vs '#(pi e)
(define two-students (vector "Ogechi" "Katherine")) vs.
(define dos-estudientes '#("Ogechi" "Katherine"))
(vector-set! two-students 0 "Oge")
(vector-set! dos-estudientes 1 "Kat")
* What is #100(1 2 3)?
* Consider
(define emu (vector 1 2 3))
(define shark (list (vector-set! emu 1 2)))
What is emu?
What is shark?
* "Use" is ambguous
+ "Use as a helper"
+ "Use as a pattern"
(define NAME
(lambda (lst)
(if (null? lst)
null
(cons (SOMETHING (car lst)) (NAME (cdr lst))))))