Determine if a word or phrase is an isogram.
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.
Examples of isograms:
The word isograms, however, is not an isogram, because the s repeats.
While Common Lisp doesn't care about indentation and layout of code, nor whether you use spaces or tabs, this is an important consideration for submissions to exercism.io. Excercism.io's code widget cannot handle mixing of tab and space characters well so using only spaces is recommended to make the code more readable to the human reviewers. Please review your editors settings on how to accomplish this. Below are instructions for popular editors for Common Lisp.
Use the following commands to ensure VIM uses only spaces for indentation:
:set tabstop=2 :set shiftwidth=2 :set expandtab
(or as a oneliner
:set tabstop=2 shiftwidth=2 expandtab). This can
be added to your
~/.vimrc file to use it all the time.
Emacs is very well suited for editing Common Lisp and has many powerful add-on packages available. The only thing that one needs to do with a stock emacs to make it work well with exercism.io is to evaluate the following code:
(setq-default indent-tabs-mode nil)
This can be placed in your
order to have it set whenever Emacs is launched.
One suggested add-on for Emacs and Common Lisp is SLIME which offers tight integration with the REPL; making iterative coding and testing very easy.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
(ql:quickload "lisp-unit") #-xlisp-test (load "isogram") (defpackage #:isogram-test (:use #:common-lisp #:lisp-unit)) (in-package #:isogram-test) (define-test empty-string (assert-true (isogram:is-isogram ""))) (define-test isogram-with-only-lower-case-characters (assert-true (isogram:is-isogram "isogram"))) (define-test word-with-one-duplicated-character (assert-false (isogram:is-isogram "eleven"))) (define-test longest-reported-english-isogram (assert-true (isogram:is-isogram "subdermatoglyphic"))) (define-test word-with-duplicated-character-in-mixed-case (assert-false (isogram:is-isogram "Alphabet"))) (define-test hypothetical-isogrammic-word-with-hyphen (assert-true (isogram:is-isogram "thumbscrew-japingly"))) (define-test isogram-with-duplicated-hyphen (assert-true (isogram:is-isogram "six-year-old"))) (define-test made-up-name-that-is-an-isogam (assert-true (isogram:is-isogram "Emily Jung Schwartzkopf"))) (define-test duplicated-character-in-the-middle (assert-false (isogram:is-isogram "accentor"))) #-xlisp-test (let ((*print-errors* t) (*print-failures* t)) (run-tests :all :isogram-test))
(defpackage #:isogram (:use #:cl) (:export #:is-isogram)) (in-package #:isogram) (defun is-isogram (string) (let ((cleaned (loop for x across (string-downcase string) when (char<= #\a x #\z) collect x))) (= (length cleaned) (length (remove-duplicates cleaned)))))
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.