alpha-char-p
alpha-char-p Function
Syntax:
alpha-char-p character → generalized-boolean
Arguments and Values:
character—a character .
generalized-boolean—a generalized boolean.
Description:
Returns true if character is an alphabetic1 character ; otherwise, returns false.
Examples:
(alpha-char-p #\a) → true
(alpha-char-p #\5) → false
(alpha-char-p #\Newline) → false
;; This next example presupposes an implementation
;; in which #\*α* is a defined character.
(alpha-char-p #\*α*) → implementation-dependent
Affected By:
None. (In particular, the results of this predicate are independent of any special syntax which might have been enabled in the current readtable.)
Exceptional Situations:
Should signal an error of type type-error if character is not a character .
See Also:
alphanumericp, Section 13.1.10 (Documentation of Implementation-Defined Scripts)
Expanded Reference: alpha-char-p
Basic alphabetic character tests
alpha-char-p returns true if the character is alphabetic (a letter), and false otherwise.
(alpha-char-p #\a)
=> T
(alpha-char-p #\Z)
=> T
(alpha-char-p #\5)
=> NIL
(alpha-char-p #\+)
=> NIL
Non-graphic and whitespace characters
Whitespace and non-graphic characters are never alphabetic.
(alpha-char-p #\Space)
=> NIL
(alpha-char-p #\Newline)
=> NIL
(alpha-char-p #\Tab)
=> NIL
Filtering alphabetic characters from a string
alpha-char-p is commonly used to extract only letter characters from a string.
(remove-if-not #'alpha-char-p "Hello, World! 123")
=> "HelloWorld"
Checking if a string contains only letters
You can use every with alpha-char-p to test whether a string is purely alphabetic.
(every #'alpha-char-p "Hello")
=> T
(every #'alpha-char-p "Hello!")
=> NIL
(every #'alpha-char-p "abc123")
=> NIL
(every #'alpha-char-p "")
=> T
Relationship with alphanumericp
alpha-char-p tests for letters only, while alphanumericp also accepts digits.
(alpha-char-p #\7)
=> NIL
(alphanumericp #\7)
=> T
(alpha-char-p #\G)
=> T
(alphanumericp #\G)
=> T