EBoard 11: Lists, Continued

This class will be recorded! Its use is limited to members of the class. Please do not share with others.

Approximate overview

  • Administrative stuff [~10 min]
  • Q&A [~10 min]
  • Quiz [~10 min]
  • Lab [~60 min]

Administrative stuff

Notes and News

  • I’m working from home today, which means not only a different background, but a different monitor. Let me know if I have to adjust anything to make it bigger/smaller. Oh, you’ll also see me looking up instead of sideways. I’ll probably still squint.
  • Many of you seem to be having Internet problems today. Just keep me posted.
  • Please don’t call me “Professor” in the generic.
  • Lots of stuff returned over the weekend.
    • Please submit redos of MPs on the new Redo assignments.
    • DM me with SoLA questions.
    • Take makeup quizzes before Wednesday night.
  • Evening tutoring will be available 3-5 p.m. Sundays and 7-10 p.m. Sundays through Thursdays in the tutoring channel on the CS team.
    • If evening tutors + mentor sessions are not enough, we do have individual tutors available.
    • Evening tutors like visitors, including in-person visitors.
  • I’m still fighting with the autograders.
    • Note: .999 (or something similar) means “all correct”.
      At some point, I’ll explain why.
  • You’re doing a great job asking questions on Teams!
  • Some of you should ask more, including via DM. I’m happy to try to help when I’m available.

Upcoming activities and other token earning things

Notes

  • When appropriate, I will post details to the Announcements channel.
  • Don’t be afraid to suggest things.

Events

  • CS Table, Noon, Today, 15 February, in Events Channel on CS Team. Welcome to CS Table! [Sorry this didn’t get announced on Friday; we had some mixups on scheduling.]
  • CS Extras, 5pm, Thursday, 18 February, in Events Channel on CS Team. Random Higher-Order Network Generation
  • Get your free food from Chuong Garden Wednesday, Thursday, or Friday. (See note from Dean Marzluff on Announcements Channel.)
    • Yes, you have to write about the experience.
    • If you aren’t on campus, suggest an alternative.
  • Journalism Ethics Workshop, 7:00-8:30 pm, Thursday, March 4 and Tuesday, March 9

Upcoming work

I’m not sure if all of these links are correct. Let me know if any are not.

Attendance

  • Our wonderful mentors will take attendance by looking at the the list of also-wonderful people here.

Notes from the SoLAs

  • You can redo any missed LAs on SoLA 2 or SoLA 3 or SoLA 4 or SoLA 5.
    • I’d prefer you try on SoLA 2.
  • Please don’t put your name in quizzes or LAs. I prefer to grade those anonymously.
    • Apologies for the ableist term I have used for anonymous grading; I should know better.
  • Some of you need to work on your style. (I realize there’s a problem on it, but I saw things like

       (equal? (list->string(take(string->list (substring contact (+ (char-index contact #\|) 1)))3)) "641")))
    

    Which is way too much on one line, missing spaces, and more. You will lose points on LAs for poor style.

  • I was interested to see how many of the pair programming recommendations were just “Be a decent human being”.
    • “Be careful and kind, not rude.”
    • “Don’t interrupt.”
    • “Treat others with respect.”
    • “Listen to those you are working with.”
      • Don’t make jokes about ending sentences with a preposition.
    • “Apply one of the golden rules.”
      • “Treat others as you would like others to treat you.”
      • “Don’t treat others as you would not wish to be treated.”
    • “Don’t make condescending comments.”
      • Whoops, I think I just failed on this one.
    • “Be patient with others.”
    • “When working with others, focus on the task at hand.”
  • The Style SoLA was evil. I apologize. It will be friendlier next time.

Notes from the reading responses

  • I was interested that many of you found section to be the clearest, at last with the three ways of subtracting five. We’ll see if that continues.
  • Yes, you can use lambda for an anonymous procedure.
    • (map (lambda (x) (- x 3)) '(1 2 3 4 5))
    • (map (section - <> 3) '(1 2 3 4 5))
    • (map (o sub1 sub1 sub1) '(1 2 3 4 5))

Q&A

There’s no MP2 autograder. Why?

It appears that Sam is technologically incompetent, at least with regards to autograaders.

Maybe after class.

Why were you being mean about the code?

It was hard to read. I tend to be extreme on hard-to-read code.

Itwshrdtrd.Itndtbxtrmnhrd-t-rdcd.

Good formatting helps us read.

It was hard to read. I tend to be extreme on hard-to-read code.

Policies on formatting clearly?

Parameters to a procedure should all be on the same line or all in aligned vertically.

Try to get the first parameter on the same line as the procedure.

Try to keep lines under 80 characters.

Try to keep lines under 8 or so “words”/”units”

(define local?
  (lambda (contact)
    (equal? (list->string (take (string->list
                                 (substring contact
                                            (+ (char-index contact #\|) 1)))
                                3))
            "641")))

What should conditionals look like?

(if TEST
    CONSEQUENT 
    ALTERNATE)

(or EXP1
    EXP2
    ...)

Can I map with and and or?

Not usually.

But if you were doing (map odd? '(1 2 3 4 5)) or something similar to get a list of true and false, you could instead use andmap or ormap.

(andmap (lambda (x) x) '(#f #t #t #t))

(ormap (lambda (x) x) '(#f #t #t #t))

> (andmap (lambda (x) x) '(#f #t #t #t))
#f
> (andmap (lambda (x) x) '(#t #t #t #t))
#t
> (ormap (lambda (x) x) '(#t #t #t #t))
#t
> (ormap (lambda (x) x) '(#f))
#f

We need to have a function for andmap and ormap. We use (lambda (x) x) which is “a function that takes one parameter and returns that parameters”.

(define id (lambda (x) x))

(andmap id '(#t #f #t #f))

Could you please be nicer?

Maybe

Can I replace a character in a string?

(string-replace "abcde" "c" "Q")

Can I replace selected elements in a list?

> (define bluecow
    (lambda (x)
      (if (equal? x "cow")
          "blue"
          x)))
> (map bluecow (list "cat" "and" "cow" "jump"))
'("cat" "and" "blue" "jump")

Can I replace the value of a list at index 5?

Lists are immutable. You cannot change them. You can only build new lists.

> (define cowblue
    (lambda (lst)
      (append (take lst 5) (list "blue") (drop lst 6))))
> (cowblue (make-list 10 "cow"))
'("cow" "cow" "cow" "cow" "cow" "blue" "cow" "cow" "cow" "cow")
> (cowblue (range 1 10))
'(1 2 3 4 5 "blue" 7 8 9)

Quiz

  • Sam: Remember to talk about the lab before starting the quiz!

Lab

  • New partners!
  • Introductions / preparation.
  • Don’t forget to check the Class Meetings channel from time to time.