Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; e)
- ;; (nheight nlist) consumes a nested list nlist and returns
- ;; the height corresponding to the maximum number of lists that
- ;; have been nested
- ;; nheight: Nested-Listof-Any -> Nat
- ;; Examples:
- (check-expect (nheight empty) 1)
- (check-expect (nheight '((1))) 2)
- (define (nheight nlist)
- (nfoldr (lambda (x y) y)
- (lambda (x y) (max (+ x 1) y))
- 1
- nlist))
- ;; Test:
- (check-expect (nheight '((1) 2 ((3)))) 3)
- ;; f)
- ;; (prune nlist) consumes a nested list nlist and returns a
- ;; list where all empty nested lists have been removed
- ;; prune: Nested-Listof-Num -> Nest-Listof-Num
- ;; Examples:
- (check-expect (prune '()) empty)
- (check-expect (prune '(1 () 2)) '(1 2))
- (define (prune nlist)
- (nfoldr (lambda (x y) (cons x y))
- (lambda (x y)
- (cond
- [(empty? x) (append y)]))
- empty
- nlist))
- ;; Tests:
- (check-expect (prune '(1 2 3)) '(1 2 3))
- (check-expect (prune '(1 () 3 () (()))) '(1 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement