Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #lang racket
  2.  
  3. (define (first-uniq chars)
  4. (when (empty? chars)
  5. (raise "There are no unique letters"))
  6. (let ([c (first chars)])
  7. (if (memq c (rest chars)) ; MEMQ is like MEMBER with EQ?
  8. (first-uniq (remq* (list c) chars)) ; N.B the tail-recursion here
  9. c)))
  10.  
  11. (require rackunit)
  12. (check-equal? (first-uniq (string->list "aabcbcdeef"))
  13. #\d)
  14. (check-equal? (first-uniq (string->list "faabcbcdeef"))
  15. #\d)
  16. (check-equal? (first-uniq (string->list "aabcbcdeefd"))
  17. #\f)
Add Comment
Please, Sign In to add comment