PLQ #8Done on:   Tuesday, March 11th

Question 1 @ 2025-03-11 19:52

Which of the following definitions would be correctly implementing division?

(For simplicity, assume that it should work only for inputs that are integer-divisible.)


Question 2 @ 2025-03-11 19:55

We now know that Racket has for-each function that is similar to map except that it doesn’t collect the results into a list. Many languages have a similar functionality, for example, JS has x.forEach(...) .

Why is such functionality needed?


Question 3 @ 2025-03-11 19:56

What is the expected result of the following plain Racket code?

(define (make-thing)
  (let ([b (box 0)])
    (lambda (msg)
      (match msg
        ['+1 (set-box! b (+ 1 (unbox b)))]
        ['*2 (set-box! b (* 2 (unbox b)))]
        ['get (unbox b)]))))

(define thing-a (make-thing))
(thing-a '+1)
(define thing-b (make-thing))
(thing-a '*2)
(thing-b '+1)
(list (thing-a 'get) (thing-b 'get))

Question 4 @ 2025-03-11 19:58

In the context of implementing a programming language with a set! operation to modify variables, what is an advantage of choosing to return the value that was assigned as the behavior for set! expressions?


Question 5 @ 2025-03-11 20:00

Reminder: in Typed Racket, the following numerical subtype relationships hold:

Zero ⊆ Integer ⊆ Number

Which of the following function types are a subtype of Integer -> Integer?