-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter-study.lisp
47 lines (43 loc) · 1.16 KB
/
character-study.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(defpackage :character-study
(:use :cl)
(:export
:compare-chars
:size-of-char
:change-size-of-char
:type-of-char))
(in-package :character-study)
;;; returns the different size comparison keyword to describe the two characters
;;; case sensitive
(defun compare-chars (char1 char2)
(cond
((char= char1 char2) :equal-to)
((char> char1 char2) :greater-than)
((char< char1 char2) :less-than)
)
) ; => :greater-than, :less-than, :equal-to
;;; returns the "size" (keyword) of the character
(defun size-of-char (char)
(cond
((upper-case-p char) :big)
((lower-case-p char) :small)
(t :no-size)
)
) ; => :big, :small, :no-size
;;; returns a transformed char based on the requested transformation
(defun change-size-of-char (char wanted-size)
(case wanted-size
(:big (char-upcase char))
(:small (char-downcase char))
(otherwise char)
)
) ; => char
;;; returns the type (keyword) of the given char
(defun type-of-char (char)
(cond
((alpha-char-p char) :alpha)
((digit-char-p char) :numeric)
((char= char #\Space) :space)
((char= char #\Newline) :newline)
(t :unknown)
)
) ; => :alpha, :numeric, :space, :newline, :unknown