Programming Languages and Paradigms

Spring Semester 2018

- The quiz consists of five questions and one image. Be sure that you have all of these items and that they are all legible.
- Read all questions and their instructions thoroughly before you begin. It is always worth your time to plan ahead!
- You have also been given two blank pages. Use these sheets
for your quiz answers.
*Write your name on each sheet*. - The quiz is worth 60 points. Each question is worth twelve points.
- Keep the quiz questions when you are done, for future reference.
- Points will be awarded based on your explicit answers. Partial credit will be given where possible, so show all of your work.
- The quiz lasts thirty (30) minutes. It is due at 1:45 PM.

- Write
**brief**answers for each of the following items (two sentences each, max).- What are the
**three things**that every programming language has? - Give an example from Racket of each of the three things.
- Explain the distinction in Racket between a
**function**and**special form**. Illustrate your answer with a specific example of each. - In Racket, how does the definition of a
**variable arity**function differ from the definition of an ordinary function?

- What are the
- Answer each of these questions about the structure of Racket
lists.
- Write the Racket literal corresponding to the list shown
in this box-and-pointer diagram.

- Draw a box-and-pointer diagram that shows the structure
of this Racket list.
**(cons (list 'a 3) (cons 'b (cons 2 (list 'c 1))))**

- Write the Racket literal corresponding to the list shown
in this box-and-pointer diagram.
- Write a Racket function named
that takes three arguments, all numbers: an employee's hourly wage, the income tax rate, and the number of hours the employee worked this pay period.`take-home-pay`returns the employee's total pay after taxes have been deducted. For example:`take-home-pay`> (take-home-pay 10.00 0.15 6) ; 6 hrs * $10.00/hr, minus 15% 51.00 > (take-home-pay 15.00 0.28 40) ; a decent internship 432.00 > (take-home-pay 4.25 0.00 55) ; minimum wage, in the old days 233.75

- Write a Racket function named
that takes one arguments: a function,`sum-of-apps``f`, of one argument.`sum-of-apps`returns a two-argument function (both numbers), which applies`f`to both arguments and returns the sum of those values. For example:> (define double (lambda (n) (* n 2))) > (define square (lambda (n) (* n n))) > (define sum-of-squares (sum-of-apps square)) > ((sum-of-apps double) 3 4) ; (3*2) + (4*2) 14 ; == 14 > ((sum-of-apps square) 3 4) ; 3² + 4² 25 ; == 25 > (sum-of-squares 5 12) 169

- Suppose that we have a list containing height/weight pairs for
a group of people, in inches and pounds, respectively:
( (76 . 195) (81 . 212) (79 . 225) (71 . 206) ... )

We would like to know the average height of the people in the group who weigh more than some given amount.

Use the higher-order functions`map`,`apply`, and`filter`to write a Racket function namedthat takes two arguments: a weight`avg-height-over``w`and a list of height/weight pairs`lst`in the above form.finds the subset of`avg-height-over``lst`who weigh more than`w`and returns the average height of the people in the subset. For example:> (avg-height-over 200 '((79 . 225)) 79 > (avg-height-over 90 '((70 . 150) (62 . 100))) 66 > (avg-height-over 200 '((76 . 195) (81 . 212) (79 . 225) (71 . 206))) 77

Assume that we have already written a variable-arity function named. You may write other helper functions if you like, but you do not have to.`average`**No recursion or looping are allowed**!