EBoard 03: Writing your own procedures (Section 3)

Warning! You are being recorded (and transcribed) (provided the technology is working correctly).

Today’s start-of-class procedure

  • Take one of the business cards from outside the jar.
  • Identify where the named computer is.
  • Drop the business card in the jar.
  • Navigate to that computer.
  • If you are first, log in, but do not start the lab.
  • When a second person arrives, introduce yourself.

Note: If you need to sit in a particular area of the classroom, let me know and we’ll work things out in the future.

Approximate overview

  • Lots of administrative stuff [10 min]
  • Attendance [5 min]
  • About MP1 [5 min]
  • Questions [10 min]
  • Lab [45 min]
  • Submit [5 min]

Administrative stuff

Introductory notes

  • After talking with the mentors, I’ve decided to move quizzes to Wednesdays. (Having homework due on Thursday night and quizzes on Fridays seems inappropriate.)
  • Something went wrong with the site updates over the weekend. Sorry about that.
  • Here’s the approximate “rhythm” of the class.
    • Fridays: Class; in most weeks, mini-projects distributed; MP post-reflections due
    • Sundays: Friday’s lab due; Monday’s reading responses due; MP/SoLA pre-reflections due mentor session (?)
    • Mondays: Class; in some weeks, SoLAs distributed at the end of the day;
    • Tuesdays: Monday’s lab due, Wednesday’s reading responses due, mentor session (?)
    • Wednesdays: Class; quizzes
    • Thursdays: MPs/SoLAs due; Wednesday’s lab due; Friday’s reading responses due.
  • Sam should discuss Vygotsky’s Zone of Proximal Development.

Upcoming activities

Scholarly

Artistic

Multicultural

  • Saturday, 2025-02-01, 1:00–10:00 p.m., Harris Concert Hall. Lunar New Year Celebration.

Peer

Musical, theatric, sporting, and academic events involving this section’s students are welcome.

Pride week!

  • Monday, 2025-01-27, 4:00–6:00 p.m., SRC. Denim Dazzle Workshop
  • Wednesday, 2025-01-29, 6:00–7:30 p.m., SRC. Jotería Game Night (Win prizes!)
  • Thursday, 2025-01-30, 5:00–7:00 p.m., JRC 101. Stonewall Pridefest.
  • Friday, 2025-0131, 7:00–8:00 p.m., Harris Gym. _Covered in Melanin Drag Show.

Wellness

  • Tuesday, 2025-01-28, 12:15–12:50 p.m., GCMoA. Yoga in the Museum.
  • Tuesday, 2025-01-28, 4:30–6:30 p.m., BRAC P103 (Multipurpose Dance Studio). Wellness Yoga.
  • Tuesday, 2025-01-28, 7:30–9:00 p.m., Harris Concert Hall (aka Harris Gym). Queer Stompede
  • Wednesday, 2025-01-29, 12:00–1:00 p.m., Whale Room in the DHall. Current Events Support Space (with SHAW)

Misc

  • Thursday, 2025-01-30, 4:00–5:00 p.m., Noyce 3821. CS Major Declaration Info Session.
    • Snacks beforehand in the CS Commons.

Other good things

These do not earn tokens, but are worth your consideration.

  • Saturday, 2025-02-01, 10:00 a.m.–1:00 p.m., Field House. Grinnell Track and Field Invitational.
  • Sunday, 2025-02-02, early afternoon, Field House. Men’s Tennis.

Upcoming work

Attendance

About MP1

  • Part one: Make pieces “by hand” (well, by code)
  • Part two: Write some potentially useful procedures
  • Part three: Write a procedure to make pieces
  • Part four: Call your procedure four times to build four (specific) pieces
  • Make sure to read the rubric!

Q&A

Administrative

Why do some of my assignments say “Submitted” and some say “Ungraded”?

“Submitted” means that you’ve submitted it but I haven’t started grading the assignment.

“Ungraded” means that you’ve submitted it, and I’ve started grading the assignment, but I haven’t gotten to yours yet.

Note that “I” can also mean “the graders”.

Though I have written my own code, I have used a library created by Grinnell CS. Is it necessary to cite in this case, and if so, how do I properly cite the section of the csc151 library that I used?

If you are importing a library (in our case, with (require csc151)), you need not provide additional citations.

DrRacket

How do we go back and edit code?

I assume you’re asking about the interactions pane. On Linux and Windows boxes, it’s usually Ctrl-UpArrow and Ctrl-DownArrow. On the Mac, it’s Esc-P (previous) and Esc-N (next).

Why won’t DrRacket load the csc151 library on my computer?

I’m not sure.

Racket/Scheme

Can DrRacket’s image model use hexadecimal color?

If you mean the hex for RGB, then yes. You need to use something like (hex->rgb "AA00B7").

Why does the name of the color have to be in quotation marks, and how does DrRacket know that its a color not a string?

Actually, it’s a string that names a color. If it weren’t in quotation marks, DrRacket would think that it’s something we’ve named with define.

Decomposition

I don’t really understand the top-down design, particularly what the purpose of using ??? just to come back and replace it is.

We’ll think about this in terms of the PB&J sandwich.

Get bread. Spread peanut butter on bread. Add bananas. Eat.

Open jar of peanut butter. Remove spoonful of peanut butter. Add to bread. Spread with knifer.

Grab jar with lid facing upward using your dominant hand. Grab lid of jar with other hand. …

History suggests that this is a good way of thinking about problem solving.

Procedures

Can we go over the specific parts of a procedures

Certainly.

A procedure (subroutine, functions, methods) is a named collection of code that takes input.

Three things to think about in how we write procedures in almost any programming language.

  • The name. How will we refer to the procedure in the future?
  • The inputs. How will we refer to the inputs in the body of the procedure? (In some languages, we give both names and types (integer, string, color, …) to inputs; in Scheme, we only give names.)
  • The body: What the procedure actually does/computes.

In Scheme, we write

(define NAME
  (lambda (INPUTS)
    BODY))

Suppose we want a procedure that surrounds an image with semi-circles.

(define surround-with-semi-circles
  (lambda (img color)
    (beside (wedge (* 1/2 (image-height img)) color 180)
            img
            (wedge (* 1/2 (image-height img)) color 180))))

FIXED:

(define surround-with-semi-circles
  (lambda (img color)
    (beside (rotate (solid-wedge (* 1/2 (image-height img)) 180 color) 90)
            img
            (rotate (solid-wedge (* 1/2 (image-height img)) 180 color) -90))))

I know the text mentioned we will cover lambda without define eventually but I would genuinely love to know why the idea of it being “anonymous” is so powerful.

We should talk about it next week. (Perhaps even this week.) It’s more than just the lambda.

For the check 2 in the last reading, when I wrote the code (solid-rectangle 40 20 "color"), it did not work. Why are we not supposed to use “” with color?

The quotation marks mean “Take it verbatim” rather than “treat this as an input to the method”. There’s no color named “color”, so it gives an error.

Lab

Make sure that you’re doing the lab called “procedures”. You may have to refresh your schedule.

Save save save save save.