Advertisement
DoomProg

allthewords.rkt

Apr 25th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.25 KB | None | 0 0
  1. ;; We will use racket
  2. #lang racket
  3.  
  4. ;; Take the file a put it in a list
  5. (define file-list (file->lines "/home/.../Desktop/learnxinyminutes-docs/..."))
  6.  
  7. ;; Function to print the contents of a file given a list
  8. (define (print-file-lines file-list)
  9.     (cond  ((null? file-list) (display ""))
  10.            (else
  11.                 (displayln (car file-list))
  12.                 (print-file-lines (cdr file-list)))))
  13.  
  14. ;; Call the function to show the file
  15. ;; (print-file-lines file-list)
  16.  
  17. ;; Get a set of words out of a string
  18. (define (string-to-set str)
  19.     (list->set (string-split str)))
  20.  
  21. ;; All the words in a set to lower case
  22. (define (set-to-lowercase set)
  23.     (map string-downcase (set->list set)))
  24.  
  25. ;; Get all the words in a list of strings
  26. (define (get-words list)
  27.     (let inner ((out-list '()) (list list))
  28.         (if (null? list) (list->set out-list)  
  29.                     (inner (append out-list (set-to-lowercase (string-to-set (car list)))) (cdr list)))))
  30.  
  31. ;; Prints out a list nicely
  32. (define (print-list list)
  33.   (cond ((null? list) (display ""))
  34.         (else
  35.             (displayln (car list))
  36.             (print-list (cdr list)))))
  37.  
  38. ;; Take all the different words as a list
  39. (define all-the-words (get-words file-list))
  40. ;; and print them out
  41. (print-list (set->list all-the-words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement