This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
Events
I’m not sure if all of these links are correct. Let me know if any are not.
I’ve rewritten the first problem slightly. First deal with the “base cases” (integers and symbols). Then deal with lists of integers and symbols. Then combine them.
Don’t use match with predicates (e.g., integer? and symbol?).
Use conditional
(cond
[(integer? exp)
...]
[(symbol? exp)
...]
[(list? exp)
...]
[(image? exp)
(error "No images permitted! We like text and numbers.")]
Feel free to write helper procedures.
If you want to explicitly indicate failure, use (error "Message").
See above.
What does “expensive” mean?
Usually “Will take more computing time than alternative.”
Sometimes “Will take more memory than the alternative.”
Always “Will take extra computing resources.”
Could you explain the double-dagger problem for the pairs reading?
Yes
How does match work?
That’s part of the goal of the hw.
“Is the structure of the expression ‘the same as’ the structure of the pattern?” If so, bind variables and evaluate. If not, go on.
In patterns, most words are treated as variables rather than constants to match
(match exp
[(cons (cons a b) c) ; Will match pairs whose first element is a pair; a is the car of the subpair, b is the cdr of the subpair, c is the cdr of the outer pair
...]
[x ; will match anything and call it x
...]
[integer? ; will match anything and call it integer?
...]
[null ; will match anything and call it null
...])
How should we cite?
Preferably at the top and in the code.
;;; (matchstick exp) -> any?
;;; exp : any
;;; Does something cool with exp, using match
;;;
;;; I based my `match` expression on the class notes from
;;; class 25 of CSC-151-01 2021SpT1.
;;;
;;; Sten and Bella helped me debug my code.
I have a list of symbols and integers that I want to convert to a list of integers. How do I do that?
Figure out how to convert any individual member of that list (see problem 1a)
Do that to every member of the list. Use
mapor recursion. * Possiblyapplyorfold
The reading on vectors had documentation in the other styles. How do we use our style for “it doesn’t return anything”?
Use void? as the return type
;;; (decrement-all-by-one? nums) -> void?
;;; nums : vectorof number?
;;; Subtract one from each value in nums, in place.