Advertisement
Fel1x

Untitled

May 2nd, 2024
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.48 KB | None | 0 0
  1. #lang racket
  2. (define (rev lst)
  3.   (match lst
  4.     ['() '()]
  5.     [(list a) (list a)]
  6.     [(cons h t)
  7.       (append
  8.         (rev t)
  9.         (list h))]))
  10.  
  11. (define (annihilate lst pred)
  12.   (match lst
  13.     ['() '()]
  14.     [(list a) (if (pred a) '() (list a))]
  15.     [(cons h t)
  16.       (let ([nt (annihilate t pred)])
  17.         (if (pred h)
  18.           nt
  19.           (cons h nt)))]))
  20.      
  21. (displayln (annihilate '(1 2 3 4 5 6 7 8 9 10) (λ (n) (odd? n))))
  22. (displayln (rev '(1 2 3 4 5 6)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement