Advertisement
Guest User

d

a guest
Nov 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. ;; d)
  2.  
  3. ;; (nreverse nlist) consumes a Nested-Listof-Any nlist and reverses
  4. ;; every nested list
  5. ;; nreverse: Nested-Listof-Any -> Nested-Listof-Any
  6. ;; Examples:
  7. (check-expect (nreverse (list 1 3 (list 7 9))) (list (list 9 7) 3 1))
  8. (check-expect (nreverse empty) empty)
  9.  
  10. (define (nreverse nlist)
  11. (nfoldr (lambda (x y) (append y (list x)))
  12. (lambda (x y) (append y (list x)))
  13. empty
  14. nlist))
  15.  
  16. ;; Test:
  17. (check-expect (nreverse (list (list 1 2)(list 3 4))) (list (list 4 3)(list 2 1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement