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
lambda (λ) a bit more.
Given the following sorting function:
;; sort-a : [Listof Number] -> [Listof Number]
;; to construct a list with all items from alon in increasing order
(define (sort-a 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) (sort-a (rest alon)))])))
Design an abstracted version of the
sort-a function which consumes the comparison as an additional argument and uses a loop function.
Use this function to design
sort-descending, which sort a [Listof Number] in ascending and descending order, respectively.
Decide which of the following phrases are legal lambda-expressions:
Explain why they are legal or illegal.
(lambda (x y) (x y y))
(lambda () 10)
(lambda (x) x)
(lambda (x y) x)
(lambda x 10)
In an arithmetic sequence, a0, a1, a2,..., an, an+1,..., each successor term an+1 is the result of adding a fixed constant to an. 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
a-fives, which consumes a natural number and recursively determines the corresponding term in the above series.
(a-fives 0) -> 8
(a-fives 1) -> 13
Develop the function
seq-a-fives, which consumes a natural number
n and creates the sequence of the first
n terms according to
a-fives. Hint: Use
DrRacket has lots of great abstract functions for processing lists
(pg. 313, Sect. 21.2, or the online version).
Given the following data definitions:
Design the requested functions to
;; A Grade is: (make-grade Symbol Number)
(define-struct grade (letter num))
;; The Symbol in a Grade represents
;; 'A >= 90
;; 'B >= 80
;; 'C >= 70
;; 'D >= 60
;; 'F < 60
;; A [Listof Grades] ...
(list (make-grade 'D 62) (make-grade 'C 79) (make-grade 'A 93) (make-grade 'B 84)
(make-grade 'F 57) (make-grade 'F 38) (make-grade 'A 90) (make-grade 'A 95)
(make-grade 'C 76) (make-grade 'A 90) (make-grade 'F 55) (make-grade 'C 74)
(make-grade 'A 92) (make-grade 'B 86) (make-grade 'F 43) (make-grade 'C 73)))
Grades. You must use the given list
as one of your tests.
For each you may use a
Note: if you do not use the DrRacket loop function
mentioned, you will not recieve credit for the sub-problem!
local function or
an anonymous (
- Design the function
log->lon that converts
[listof Grade] into a
[Listof Number] that
contains just the numerical grade, using the Scheme
foldr, design the function
that finds the highest Grade in a
- Design a function
just-As that returns a list of only
'A grades, using
andmap to design the
all-pass? that checks to see if all the
Grades in a given list are not
- 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
design your function... it must return a