PasteRack.org
Paste # 2926
2013-10-09 16:07:16

Forked from paste # 5485.

Fork as a new paste.

Paste viewed 314 times.


Embed:

quibble

  1. #lang racket
  2. (define (quibble words)
  3.   (define (quibble-helper words)
  4.     (match words
  5.       [(list) ""]
  6.       [(list a) a]
  7.       [(list a b) (format "~a and ~a" a b)]
  8.       [_ (format "~a, ~a" (first words) (quibble-helper (rest words)))]))
  9.   (format "{~a}" (quibble-helper words)))
  10.  
  11. (module+ test
  12.   (require rackunit)
  13.   (define (test-quibble expected words)
  14.     (check-equal? expected (quibble words)))
  15.  
  16.   (test-quibble "{}" empty)
  17.   (test-quibble "{ABC}" (list "ABC"))
  18.   (test-quibble "{ABC and DEF}" (list "ABC" "DEF"))
  19.   (test-quibble "{ABC, DEF, G and H}" (list "ABC" "DEF" "G" "H")))

=>

eval:2:0: module+: allowed only in a module body

  in: (module+ test (require rackunit) (define (test-quibble

expected words) (check-equal? expected (quibble words)))

(test-quibble "{}" empty) (test-quibble "{ABC}" (list

"ABC")) (test-quibble "{ABC and DEF}" (list "ABC" "DEF"))

(test-quibble "{ABC, DEF, G a...