EBoard 25: Vectors and Pairs

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]
  • Lab [~70 min]

Administrative stuff

Notes and News

  • Happy Friday! I hope you have an awesome weekend.
  • When you are starting a lab, make sure the text at the top of the code has the correct term (Spring Term 1 2021). If not, you probably have the wrong version of the lab.
  • As you may have noticed, we have a few slots available in CSC-161 next term. To provide equitable access to the Spring Two CSC-161, we did not allow students to pre-register for both CSC-151 in term 1 and CSC-161 in term 2. We will be holding a weighted lottery for the open slots next week. If you would like to be included in the lottery, please send an email to me at rebelsky@grinnell.edu by 5pm on Monday, 8 March 2021.
  • Today’s autograder did not build correctly. I may need to take a look at it.

Upcoming activities and other token-earning things

Events

Upcoming work

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

Some notes on MP5

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.

Q&A

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 map or recursion. * Possibly apply or fold

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.

Lab