Return true if character is a vowel in US English.

Given a string representation of a character c in the US-ASCII character set, return true if c is a vowel in written United States English.

1
2
3
""  ⟹ false
"b" ⟹ false
"a" ⟹ true

Compiled as Common Lisp using GNU CLISP.

Solution

1
2
3
4
(defun isvowel-asc-eng (c)
  (let ((VOWEL_ASC_ENG "aeiouAEIOU"))
  (and (not (zerop (length c)))
     (not (eq (search c VOWEL_ASC_ENG) nil)))))

Tests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(load "isvowel-asc-eng")

; https://github.com/OdonataResearchLLC/lisp-unit
(load "../../../lisp-unit")
(use-package :lisp-unit)

(define-test isvowel-asc-eng-empty-string-test
  (assert-false (isvowel-asc-eng "")))

(define-test isvowel-asc-eng-consonant-test
  (assert-false (isvowel-asc-eng "b")))

(define-test isvowel-asc-eng-vowel-test
  (assert-true (isvowel-asc-eng "a")))

(setq *print-errors* t)
(setq *print-failures* t)
(setq *print-summary* t)
(run-tests)