Advertisement
skbtwiz

Untitled

May 21st, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.00 KB | None | 0 0
  1. ;; (space-added-list L) consumes a non-empty (listof Str) and return the list
  2. ;;    with a space added at the beginning of each word other than the first one
  3. ;; space-added-list : (listof Str) -> (listof Str)
  4. ;; Example :
  5. (check-expect (space-added-list (list "Hello" "how" "are" "you?"))
  6.               (list "Hello" " how" " are" " you?"))
  7.  
  8. (define (space-added-list L)
  9.   (append (list (first L))
  10.           (map (lambda (x) (string-append " " x)) (rest L))))
  11.  
  12.  
  13. ;; (join L) consumes a non-empty (listof Str), and returns the Str that results
  14. ;;     from appending all the values in L, with a space (" ") between them
  15. ;; join : (listof Str) -> Str
  16. ;; requires : L is a non-empty list
  17. ;; Example :
  18. (check-expect (join (list "Hello" "how" "are" "you?")) "Hello how are you?")
  19.  
  20. (define (join L)
  21.   (foldr string-append "" (space-added-list L)))
  22.  
  23. ;; Tests :
  24. (check-expect (join (list "I" "am" "fine" "thanks!")) "I am fine thanks!")
  25. (check-expect (join (list "How" "is" "your" "job?")) "How is your job?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement