Approximate overview
Events
Other good things
Style
I’ve seen the following a few times.
(define whitespace
(rex-any-of (rex-string (string #\space))
(rex-string (string #\newline))
(rex-string (string #\tab))))
(define whitespace-sequence
(rex-repeat (rex-any-of (rex-string (string #\space))
(rex-string (string #\newline))
(rex-string (string #\tab)))))
I like the definition of whitespace.
Why don’t I like that definition of whitespace-sequence?
Using names
Consider the following …
(define book-characters (file->chars "pg1260.txt"))
(define first-20-characters (take (file->chars "pg1260.txt") 20))
Why don’t I like that?
Comments
I’ve written comments on many of your problems, whether they are correct or not. Please take the time to skim them and DM me if you have questions.
Warning I tend to give suggestions for improvement, rather than compliments. I may understand the sandwich method even less well than DrRacket.
If you missed three or more problems, please set up an appointment with me. Either use https://bit.ly/book-samr or the Teams appointment suggestion feature.
Test your code
You have access to DrRacket. Make sure to test your code!
Spaces
Spaces are good (perhaps even essential).
(lambda(x)(filter(section equal? <> x)(...)))(lambda (x) (filter (section equal? <> x) (...)))Other formatting issues
(define swap-ends
(lambda (str)
(string-append
(substring str (- (string-length str) 1) (string-length str))
(substring str 1 (- (string-length str) 1))
(substring str 0 1))))
vs
(define swap-ends
(lambda (str)
(string-append (substring str (- (string-length str) 1) (string-length str))
(substring str 1 (- (string-length str) 1))
(substring str 0 1))))
vs
(define swap-ends
(lambda (str)
(string-append (substring str
(- (string-length str) 1)
(string-length str))
(substring str
1
(- (string-length str) 1))
(substring str
0
1))))
vs
(define swap-ends
(lambda (str)
(string-append(substring str(- (string-length str) 1)(string-length str))(substring str 1 (- (string-length str) 1))(substring str 0 1))))
Naming
Please choose names that describe clearly what you are naming. (A few of you chose names that described how you were using them. A few chose pointless names.)
Naming, revisited
If we say to use a particular name for a procedure or variable, please do so. We may have some automated testing code. It’s also good practice.
Documentation
Some of you documented. If you documented, you may have received notes on your documentation. We’ll be talking a bit more about documentation (Wednesday).
Avoid display
Please don’t use display to return a string. display prints
strings. If you want to use the string, such as in string-append,
you need to just give the string.
(define name1
(lambda ()
"SamR"))
(define name2
(lambda ()
(display "SamR")))
> (substring (name1) 0 3)
> (substring (name2) 0 3)
Tracing
Enough of you got this “close, but not right”, that I’m going to go over it.
(define f
(lambda (x y)
(string-append x "[" y "]" x)))
(define g
(lambda (x y)
(string-append (f x y) "-" (f y x))))
(define h
(lambda (x)
(g x (string-append x x))))
We want to trace (h "."). We have two rules. What are they?
* *
We’re ready to go.
(h ".")
--> (g "." (string-append "." "."))