Use the Intermediate Student with lambda
language level. You can choose to use lambda
, as appropriate, in any of the assigned problems. [For 2011: You may not use local
to define functions; all program functions (including helpers) must be defined at the top level.]
Book Problems:
(define (my-max lon) (cond [(empty? lon) (error 'my-max "applied to no arguments")] [(empty? (rest lon)) (first lon)] [else (local [(define head (first lon)) (define max-tail (my-max (rest lon)))] (if (>= head max-tail) head max-tail))])) |
(define (my-max1 lon1) (cond [(empty? lon1) (error 'my-max "applied to no arguments")] [(empty? (rest lon1)) (first lon1)] [else (local [(define head2 (first lon1)) (define max-tail2 (my-max1 (rest lon1)))] (if (>= head2 max-tail2) head2 max-tail2))])) |
make-sort
.make-sort
produces functions. Test these results by applying them to a few different arguments.greg
is (4, -4/3, 4/5, -4/7, ...).(lambda (f g x) (f x (lambda (x) (g (g x))))) |
(lambda (f1 g1 x1) (f1 x1 (lambda (x2) (g1 (g1 x2))))) |
; compose : ? ; Purpose: (compose f g) returns the result of composing functions f and g: x |-> f(g(x)) (define (compose f g) (lambda (x) (f (g x)))) |
mergesort
function as described in exercise 26.1.2, except decompose the problem "top-down" rather than "bottom-up". You will need to define a function split: (list-of number) -> (list-of (list-of number))
that partitions its input into two lists of approximately (+/- 1) the same length in O(n) time where n is the length of the input list. (split l)
returns a list containing two lists of numbers. After splitting the list in half, mergesort
recursively sorts each half and then merges them together.