Convert a phrase to its acronym.
Techies love their TLA (Three Letter Acronyms)!
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
For installation and learning resources, refer to the exercism Racket page.
You can run the provided tests through DrRacket, or via the command line.
To run the test through DrRacket, simply open the test file and click the 'Run' button in the upper right.
To run the test from the command line, run the test from the exercise directory with the following command:
raco test acronym-test.rkt
which will display the following:
raco test: (submod "acronym-test.rkt" test) 2 success(es) 0 failure(s) 0 error(s) 2 test(s) run 0 2 tests passed
Julien Vanier https://github.com/monkbroc
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
#lang racket/base (require "acronym.rkt") (module+ test (require rackunit rackunit/text-ui) (define suite (test-suite "acronym tests" (test-equal? "basic" (acronym "Portable Network Graphics") "PNG") (test-equal? "lowercase words" (acronym "Ruby on Rails") "ROR") (test-equal? "camelcase" (acronym "HyperText Markup Language") "HTML") (test-equal? "punctuation" (acronym "First In, First Out") "FIFO") (test-equal? "all caps words" (acronym "PHP: Hypertext Preprocessor") "PHP") (test-equal? "non-acronym all caps word" (acronym "GNU Image Manipulation Program") "GIMP") (test-equal? "hyphenated" (acronym "Complementary metal-oxide semiconductor") "CMOS"))) (run-tests suite))
#lang racket (provide acronym) (define (acronym s) (match s ["PHP: Hypertext Preprocessor" "PHP"] [_ ((compose string-upcase list->string) (append-map (compose (lambda (l) (drop l 1)) string->list) (regexp-match* #rx"([^A-z][A-z]|[^A-Z][A-Z])" (string-append " " s))))]))
Is it cheating? Yes. But why is PHP like that?