Racket Practice

CSCI 301

These problems are intended to help you prepare for the midterm exam. As such, I recommend trying them on paper before using a computer to help you determine whether your solution was correct.

  1. Evaluate and give the value of each of the following Racket expressions.
; 1
(+ 2 (+ 3 (* 4 (- 5))))

; 2
(= 4 (+ (* 2 2) (- 4 (- (- 4)))))

; 3
(let ((x (lambda (y) (+ y y)))
      (z (lambda (q) 4)))
  (cons (x (z 6)) (z (x 6))))

; 4
(map (lambda (y) (+ y 2)) '(1 1 2))

; 5
(cadddr '(1 (2 3) 4 (5)))

; 6
(let* ((x 2)
       (y (+ 2 x))
       (f (lambda (x) (+ x y))))
  (+ (f x) (f y)))
  1. Define a Racket function longest-sublist that takes a list of lists and returns the length of the longest sublist contained therein. The length of the longest sublist of the empty list is zero. Assume that inputs are valid; that is, the input that is either the empty list or a list of lists. You do not need to check that this is the case or ensure that your program behaves in any way for invalid inputs. You may use the max and length functions. Here are a couple example cases:

    (longest-sublist '(())) ; 0
    (longest-sublist '(() (1) (1 2) (1 2 3) (1))) ; 3