Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; We will use racket
- #lang racket
- ;; Take the file a put it in a list
- (define file-list (file->lines "/home/.../Desktop/learnxinyminutes-docs/..."))
- ;; Function to print the contents of a file given a list
- (define (print-file-lines file-list)
- (cond ((null? file-list) (display ""))
- (else
- (displayln (car file-list))
- (print-file-lines (cdr file-list)))))
- ;; Call the function to show the file
- ;; (print-file-lines file-list)
- ;; Get a set of words out of a string
- (define (string-to-set str)
- (list->set (string-split str)))
- ;; All the words in a set to lower case
- (define (set-to-lowercase set)
- (map string-downcase (set->list set)))
- ;; Get all the words in a list of strings
- (define (get-words list)
- (let inner ((out-list '()) (list list))
- (if (null? list) (list->set out-list)
- (inner (append out-list (set-to-lowercase (string-to-set (car list)))) (cdr list)))))
- ;; Prints out a list nicely
- (define (print-list list)
- (cond ((null? list) (display ""))
- (else
- (displayln (car list))
- (print-list (cdr list)))))
- ;; Take all the different words as a list
- (define all-the-words (get-words file-list))
- ;; and print them out
- (print-list (set->list all-the-words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement