fork download
  1. #lang racket
  2.  
  3. (require (only-in srfi/1 lset-adjoin))
  4.  
  5. ; copy-list
  6. (define (our-copy-list lst)
  7. (foldr (lambda (x f) (cons x f)) '() lst))
  8.  
  9. ; remove-duplicates
  10. (define (our-remove-duplicates lst)
  11. (foldr (lambda (x f) (lset-adjoin eqv? f x)) '() lst))
  12.  
  13. ; find-if
  14. (define (our-find-if fn lst)
  15. (foldr (lambda (x f) (if (fn x) x f)) #f lst))
  16.  
  17. ; some
  18. (define (our-some fn lst)
  19. (foldr (lambda (x f) (or (fn x) f)) #f lst))
  20.  
  21. ;; テスト
  22. ; our-copy-list
  23. (define *lst* (list 1 (list 2 3)))
  24. (define *clst* (our-copy-list *lst*))
  25. (eq? *clst* *lst*)
  26. (equal? *clst* *lst*)
  27.  
  28. ; our-remove-duplicates
  29. (our-remove-duplicates '(a b c b d d e))
  30.  
  31. ; our-find-if
  32. (our-find-if even? '(3 1 4 1 5 9))
  33.  
  34. ; our-some
  35. (our-some integer? '(1 3 b 2.7))
  36. (our-some integer? '(a 3.1 b 2.7))
  37.  
Success #stdin #stdout 0.7s 89136KB
stdin
Standard input is empty
stdout
Standard output is empty