Sample Questions: SICP Section 2.4

Data-directed programming and generic operators.

  1. Define a version of the apply-generic function for binary operators. Do not implement a variadic function. Do not implement any error checking.
  1. Redefine the make-rat procedure to use a dispatch function. Handle the messages, numer, denom, and mult.
  1. Define a version of the apply-generic function for binary operators in which the operands are message passing procedures. Do not implement a variadic function. Do not implement any error checking.
  1. Consider re-implementing apply-generic (from the text) for just binary operations on tagged data. If no error checking is to be performed, what would be a valid function body? Assume the formal parameters are op, left, and right and that functions installed in the operator table work on tagged operands. Choose the correct answer with the fewest number of printable characters.
    1. ((get op)
          left
          right)
      
    2. (apply
          (get op (type-tag left) (type-tag right))
          (list left right))
    3. (op
          left
          right)
      
    4. ((get op (map type-tag (list left right)))
          left
          right)
      

    5. ((get op (type-tag left) (type-tag right))
          left
          right)
      
    6. (apply
          (get op (map type-tag (list left right)))
          (list left right))