EBoard 14: Local Bindings

Approximate overview

  • Administrative stuff [5 min]
  • Some quick notes from Friday’s lab [5 min]
  • Some notes from the SoLA [10 min]
  • Q&A [5 min]
  • Lab [55 min]

Administrative stuff

Introductory Notes

  • Happy Monday!
  • New partners and places!
  • I was less successful at grading this weekend than I might have hoped. The SoLAs are done. Nothing else is. I’ll keep plugging along (at least I hope I will).
  • Congrats to volleyball for two great wins!
  • Please read over the body of today’s eboard and send me comments.

Monday PSA

  • It’s Monday. The start of the week.
  • In my twenty-five years at Grinnell, I’ve seen bad things happen on weekdays.
  • Remember: Moeration in studying!
  • And SLEEP IS ESSENTIAL.

Upcoming activities

Events

  • Learning from CS Alumni Tuesday 2:00 p.m. in Science 3821.
  • Mentor Session Tuesday 8:00 p.m. in the CS commons.
  • Pioneer Weekend introductory talk, 7:00 p.m. Friday, October 1.
  • Pioneer Weekend, October 1–3.

Other good things

Upcoming work

Quick notes from Friday’s lab

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?

Notes from the SoLA

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).

  • Not (lambda(x)(filter(section equal? <> x)(...)))
  • But (lambda (x) (filter (section equal? <> x) (...)))
  • Afterall,youdon’twriteallofyourwordsmushedtogether.

Other formatting issues

  • Try to keep your lines moderately short (not too many “words”); it helps with readability.
  • However, it’s generally good to put the first parameter to a procedure call on the same line as the procedure.
(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 "." ".")) 

Q&A

Lab