 Due date: 11/14 @ 11:59pm Programming Language: Intermediate Student Language with lambda
The goal of this problem set is to practice using DrRacket's loop
functions. In addition we will look
into local
and lambda (λ) a bit more.
Problem A1:
Given the following sorting function:
;; sorta : [Listof Number] > [Listof Number]
;; to construct a list with all items from alon in increasing order
(define (sorta alon)
(local ((define (insert an alon)
(cond [(empty? alon) (list an)]
[( < an (first alon)) (cons an alon)]
[else (cons (first alon)
(insert an (rest alon)))])))
(cond [(empty? alon) empty]
[else (insert (first alon) (sorta (rest alon)))])))
Design an abstracted version of the sorta function which consumes the comparison as an additional argument and uses a loop function.
Use this function to design sortascending and sortdescending , which sort a [Listof Number] in ascending and descending order, respectively.
Problem A2:
Decide which of the following phrases are legal lambdaexpressions:

(lambda (x y) (x y y))

(lambda () 10)

(lambda (x) x)

(lambda (x y) x)

(lambda x 10)
Explain why they are legal or illegal.
Problem A3:
In an arithmetic sequence, a_{0}, a_{1}, a_{2},..., a_{n}, a_{n+1},..., each successor term a_{n+1} is the result of adding a fixed constant to a_{n}. For example, the sequence 8, 13, 18, 23, ... has a starting point of 3 and the constant is 5. From these two facts, called starting point and summand, respectively, all other terms in the sequence can be determined.

Develop the recursive function
afives , which consumes a natural number and recursively determines the corresponding term in the above series.
(afives 0) > 8
(afives 1) > 13

Develop the function
seqafives , which consumes a natural number n and creates the sequence of the first n terms according to afives . Hint: Use buildlist .
Problem A4:
DrRacket has lots of great abstract functions for processing lists
(pg. 313, Sect. 21.2, or the online version).
Given the following data definitions:
;; A Grade is: (makegrade Symbol Number)
(definestruct grade (letter num))
;; The Symbol in a Grade represents
;; 'A >= 90
;; 'B >= 80
;; 'C >= 70
;; 'D >= 60
;; 'F < 60
;; A [Listof Grades] ...
(define grades
(list (makegrade 'D 62) (makegrade 'C 79) (makegrade 'A 93) (makegrade 'B 84)
(makegrade 'F 57) (makegrade 'F 38) (makegrade 'A 90) (makegrade 'A 95)
(makegrade 'C 76) (makegrade 'A 90) (makegrade 'F 55) (makegrade 'C 74)
(makegrade 'A 92) (makegrade 'B 86) (makegrade 'F 43) (makegrade 'C 73)))
Design the requested functions to
manipulate Grades . You must use the given list
as one of your tests.
For each you may use a local function or
an anonymous (lambda ) function.
Note: if you do not use the DrRacket loop function
mentioned, you will not recieve credit for the subproblem!
 Design the function
log>lon that converts
a [listof Grade] into a [Listof Number] that
contains just the numerical grade, using the Scheme
function map .
 Using
foldr , design the function bestgrade
that finds the highest Grade in a [Listof
Grade] .
 Design a function
justAs that returns a list of only
the 'A grades, using filter .
 Use
andmap to design the
function allpass? that checks to see if all the
Grades in a given list are not 'F .
 Finally design the function
bonus that adds 5
to all of the Grades in a given list, and updates the letter
portion of the Grade if it changes. Use map to
design your function... it must return a [Listof
Grade] !
