Warning This class is being recorded (and transcribed), provided Sam remembered to hit the “Record” button.
Approximate overview
Academic
Cultural
Peer
Wellness
Misc
Please put these in your notes!
Due to nearly every procedure referencing numerous others, it was difficult to trace where errors occurred when calling the final top level procedure.
Write tests!
Ask Sam!
I couldn’t find time to meet with Sam.
Email and Teams Messages work (or usually work). If Sam doesn’t respond promptly, please ask again.
Evening tutors might be able to help.
Classmates might be able to help.
It was frustrating that I thought I was done and then learned that there were issues I hadn’t thought about when I got results from the autograder.
Don’t forget that you can run the autograder at any point and see the kinds of things I’m looking for. (You only see the input, but that plus the text should give you some ideas.)
I would have liked more class time on bitmaps.
Sorry. Sometimes the learning has to happen in the mini-projects.
I couldn’t figure out how to do X.
Did you ask anyone?
I would have benefited from reading through the prompts to begin thinking about the problems, even before actually starting.
That’s one of the reasons I give you a pre-assessment.
Many questions and their answers can be found at the end of MP7.
How do we rotate a word?
The things we create with text/font are images, so we can just use the image procedures (
rotate).
Can I sort a list of abstract data types according to any component?
Yes.
; word-info: A collection of the word, its frequency (0..100 scale), its type
(define word-info vector)
(define word-info-word (cut (vector-ref <> 0)))
(define word-info-frequency (cut (vector-ref <> 1)))
(define word-info-type (cut (vector-ref <> 2)))
(define sample
(list (word-info "hello" 3 "greeting")
(word-info "hi" 10 "greeting")
(word-info "CSC151" 1 "proper noun")
(word-info "Sam" 3 "improper noun")
(word-info "throws" 10 "transitive verb")
(word-info "cans" 3 "proper noun (plural)")))
> (map word-info-type sample)
'("greeting"
"greeting"
"proper noun"
"improper noun"
"transitive verb"
"proper noun (plural)")
> (sort sample (lambda (wi1 wi2) (string-ci<=? (word-info-word wi1) (word-info-word wi2))))
'(#("cans" 3 "proper noun (plural)")
#("CSC151" 1 "proper noun")
#("hello" 3 "greeting")
#("hi" 10 "greeting")
#("Sam" 3 "improper noun")
#("throws" 10 "transitive verb"))
> (sort sample (lambda (wi1 wi2) (string-ci<=? (word-info-type wi1) (word-info-type wi2))))
'(#("hi" 10 "greeting")
#("hello" 3 "greeting")
#("Sam" 3 "improper noun")
#("CSC151" 1 "proper noun")
#("cans" 3 "proper noun (plural)")
#("throws" 10 "transitive verb"))
> (sort sample (lambda (wi1 wi2) (<= (word-info-frequency wi1) (word-info-frequency wi2))))
'(#("CSC151" 1 "proper noun")
#("cans" 3 "proper noun (plural)")
#("Sam" 3 "improper noun")
#("hello" 3 "greeting")
#("throws" 10 "transitive verb")
#("hi" 10 "greeting"))
> (sort sample (lambda (wi1 wi2) (>= (word-info-frequency wi1) (word-info-frequency wi2))))
'(#("throws" 10 "transitive verb")
#("hi" 10 "greeting")
#("cans" 3 "proper noun (plural)")
#("Sam" 3 "improper noun")
#("hello" 3 "greeting")
#("CSC151" 1 "proper noun"))
Do we need to include the type of speech?
No. It was just part of the example.
Have you figured out what you’re doing about missing metacognitive reflections?
The policy has always been “You are permitted to miss up to six total labs, readings, and metacognitive reflections.” I think that remains reasonable.
I have added a policy that if your LAs and MPs indicate a passing grade, then missing tokens, labs, readings, or metacognitive reflections cannot drop you below a C. I also think that seems reasonable.
If you don’t think that’s reasonable, please meet with me.
Why did you give us this reading?
Because I’m not doing my job as a CS instructor unless I get you to think about the implications of computing. (I need to do more of it.)
How would you solve the first self check?
Write a procedure,
(name->string name), that takes a name and converts it to the appropriate string.name->stringshould work no matter what representation we use, even if we use a representation we have not yet covered.
Conceptual answer: Build a list of the five components. Filter out the non-strings. Join them with a space between them.
(define name->string
(lambda (name)
(reduce (cut (string-append <> " " <>))
(filter string?
(list (name-prefix name)
(name-given name)
(name-middle name)
(name-family name)
(name-suffix name))))))
What’s wrong with this solution to the self check?
;;; (filter pred? lst) -> lst
;;; pred? : predicate? (applicable to elements of lst)
;;; lst : list? (with elements applicable to pred?)
;;; Returns a new list of only elements of lst for which pred? is not false.
(define filter
(lambda (pred? lst)
(if (pred? (car lst))
(cons (car lst) (filter pred? (cdr lst)))
(cons null (filter pred? (cdr lst))))))
That sounds like a TPS activity to me!
There is no base case. This will run until it crashes.
You don’t really want to cons null onto the front of the list, since it will add “null” to the list (rather than not changing the list).
Is the point of this to understand how these important procedures like
map and filter came about (showing the underlying mechanisms now that
we have more knowledge)?
Yes, that’s one of the key points. We can write most of the procedures we use.
Another point is that we can pass functions as parameters. (We’ve done that many times.) You can also write procedures that accept procedures as parameters.
A third point is that we can return procedures from procedures.
How would you solve the self check?
(define filter
(lambda (pred? lst)
(cond
[(null? lst)
null]
[(pred? (car lst))
(cons (car lst) (filter pred? (cdr lst)))]
[else
(filter (pred? (cdr lst)))])))
What’s the difference between left-section and right-section?
(define fun1 (left-section - 3))(aka(cut (- 3 <>)))
(define fun2 (right-section - 3))(aka(cut (- <> 3)))
(left-section - 3)uses the3as the first parameter, which means thatfun1subtracts something from 3.
(right-section - 3)uses the3as the second parameter, which means thatfun2subtracts 3 from something.
Why would we write left-section and right-section given that
section and cut exist?
sectionandcutdon’t exist in all versions of Scheme. They also require some tools that we aren’t learning in 151.
In contrast, you have the knowledge and skills to write and understand both
left-sectionandright-section(orl-sandr-s, as many of us perfer to write them).
What does (andmap fun lst) do?
It behaves like
(and (fun v1) (fun v2) ... (fun vn)).
What’s this match thing?
Something we’re not covering. Ignore it when you see it.
Was the 45 minutes of discussion useful?
Yes. Particularly because we got a hint on the HW. (Sam’s impression of student responses.)
Yay! It’s lab time. You won’t get the whole thing done (sorry), but
“Sam, Ellie, Ella, and Michael said I can stop here!”