Warning This class is being recorded.
Approximate overview
changes.rkt file that includes a list
of the changes you’ve made in response to the grading comments.Academic
Cultural
Peer
Wellness
Misc
cut and compose (o).Design and write recursive functions over lists.
Write a recursive procedure, (increasing-length? words), that takes
a list of strings as input and ensures that every string is at least as
long as the previous string. If so, it returns true. If not, it returns
false.
Here’s a partial test suite.
(check-equal? (increasing-length '())
#t
"No strings: They are in increasing length")
(check-equal? (increasing-length? '("hello"))
#t
"A singleton")
(check-equal? (increasing-length? '("a" "b" "cd" "efg" "hij" "klmn"))
#t
"Some duplicate-length words")
(check-equal? (increasing-length? '("a" "bb" "ccc" "dddd" "eee"))
#f
"Okay until the end.")
Use cut and composition to simplify computation.
Consider the following procedures
;;; (vowel? char) -> boolean
;;; char : char?
;;; Determine if char is a vowel.
(define vowel?
(let ([vowels (string->list "aeiou")])
(lambda (ch)
(integer? (index-of vowels (char-downcase ch))))))
;;; (count-vowels str) -> integer?
;;; str : string?
;;; Count the number of vowels in str
(define count-vowels
(lambda (str)
(tally vowel? (string->list str))))
;;; (select-special-words words) -> list-of string?
;;; words : list-of string?
;;; Selects all the special words in words using the ALTV criterion.
(define select-special-words
(lambda (words)
(filter (o (cut (> <> 2)) count-vowels) words)))
a. What kinds of words does select-special-words select?
b. Explain how (o (cut (> <> 2)) count-vowels) works as a
predicate for such words.
c. Rewrite vowel? using cut and composition but no lambda.
This is a particularly evil problem. You are unlikely to get one this hard.
Consider the following procedure.
(define silly
(lambda (lst)
(map (lambda (x) (sqr (+ 1 x)))
(filter odd? lst))))
Rewrite the procedure using o and cut so that it has no lambdas.
Notes:
o when you want to sequence actions. (Do this to the parameter,
then this to the result, then this to the next result, and so on and
so forth.)cut when you want to fill in one or more parameters to a procedure,
thereby creating a new procedure._We can start with a bit of debate
cut and composemap applies a procedure to each element.filter selects elements that meet some criterion (predicate)reduce combines neighboring elements again and again and again
until we have one element.map to modify each (e.g., to convert a string to a number)reduce to combine them all into a single value.(filter ____ lst)
(cut (string-contains <> "?"))string->integer and
further-from-zero.
string->integer Returns an extact integer if the string
represents an exact integer. Otherwise, returns #f.further-from-zero Given two numbers, determines which is
further from zero.string->integer, because we get
false for anything we don’t want to process further. We get
a truish value for the things we do want to process.(filter string->integer lst)(map ____ (filter string->integer lst))
(map string->integer (filter string->integer lst))(reduce ____ (map string->integer (filter string->integer lst)))
(reduce further-from-zero (map string->integer (filter string->integer lst)))string->integer twice?
(reduce further-from-zero (filter integer? (map string->integer lst)))(reduce further-from-zero (filter string->integer lst))further-from-zero strings
instead of integers, and it expects integers.Documentation may have been the hardest one. I expect precision in your documentation, particularly with regards to the type restrictions on inputs.
Consider the following procedure that makes a simple “party person” in which we can choose the size and color of various aspects.
(define party-person
(lambda (size hat tie)
(above (triangle (* size 2) "solid" hat)
(circle (* size 2) "outline" 'black)
(beside (rotate 90 (triangle (* size 1/2) "solid" tie))
(rotate -90 (triangle (* size 1/2) "solid" tie)))
(rectangle size (* size 4) "solid" "black"))))
Here’s the result of a call to (party-person 10 "teal" "salmon").
[Image elided].
a. Document party-person using the standard format.
What’s wrong with the following answer? (TPS)
; (party-person size hat tie) -> image?
; size : number?
; hat : color?
; tie : color?
; Create a simple stick figure wearing a hat and tie, where
; the size gives a scaling factor from some basic figure. The
; hat is colored `hat` and the tie is colored `tie`. The
; figure is about 10.5*size tall and 4*size wide.
color? only returns true for RGB colors. Not for color names.number? is fairly vague … it permits numbers we probably
shouldn’t use as sizes, such as
real?)positive-real? or non-negative-real?)How would you fix it?
;;; (party-person size hat tie) -> image?
;;; size : non-negative-real?
;;; hat : either color? or color-name?
;;; tie : either color? or color-name?
;;; Create a simple stick figure wearing a hat and tie, where
;;; the size gives a scaling factor from some basic figure. The
;;; hat is colored `hat` and the tie is colored `tie`. The
;;; figure is about 10.5*size tall and 4*size wide.
Note: I’ll have a quiz on documentation available on Friday.
I’m sick of having to talk about this.
How do I pay tokens to turn something in late?
You will be charged automatically.
How do I tell how I’m doing on tokens?
Sam plans to update those this coming weekend.
When will you post the MP2 redo?
It should now be posted. Sorry for the delay.
Can I get a token for attending an event at which others are supporting me?
Only if you are also supporting someone else.
Are we charged tokens for redos on learning assessments?
Definitely not
Are you going to charge me because I turned in my mini-project five minutes late?
Probably not.
Are you going to charge me because I turned in my mini-project two to three hours late?
It depends on how much you annoy me in class with questions like this.
What should be in the changes.rkt.
What’s the difference between “shape parameter values” and “a list of shape parameter values”.
This is a shape parameter values thing:
(list 20 10 (rgb 10 10 10))
This is a list of shape parameter values lists:
(list (list 20 10 (rgb 10 10 10)) (list 30 100 (rgb 255 0 255)))