Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of sleepnova

sleepnova's solution

to Acronym in the Racket Track

Published at Aug 06 2020 · 0 comments
Test suite

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
2 tests passed


Julien Vanier https://github.com/monkbroc

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


#lang racket/base

; Tests adapted from `problem-specifications/canonical-data.json v1.7.0
(require "acronym.rkt")

(module+ test
  (require rackunit rackunit/text-ui)

  (define suite
     "acronym tests"

     (test-equal? "basic"
                  (acronym "Portable Network Graphics")

     (test-equal? "lowercase words"
                  (acronym "Ruby on Rails")

     (test-equal? "punctuation"
                  (acronym "First In, First Out")

     (test-equal? "all caps word"
                  (acronym "GNU Image Manipulation Program")

     (test-equal? "punctuation without whitespace"
                  (acronym "Complementary metal-oxide semiconductor")

     (test-equal? "very long abbreviation"
                  (acronym "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me")

     (test-equal? "consecutive delimiters"
                  (acronym "Something - I made up from thin air")

     (test-equal? "apostrophes"
                  (acronym "Halley's Comet")

     (test-equal? "underscore emphasis"
                  (acronym "The Road _Not_ Taken")

  (run-tests suite))
#lang racket

(provide acronym)

(define (acronym str)
   (for/list ([s (string-split str #rx"[ _-]+")])
     (char-upcase (string-ref s 0)))))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?