In PSL a character is its ASCII code representation. Using numeric codes to represent characters
leads to programs which are difficult to read. You are encouraged to use char to represent
(char U:id): integer macro
This macro is part of the USEFUL module. The char macro returns
the ASCII code which corresponds to the single character passed as an
argument. Char will accept alias’s for characters. An alias is established
by defining a charconst property on the property list of the alias. The
value of this property should be the ASCII code of the character which is
being aliased. The following alias’s are defined when the useful package is
|LF ||line feed |
|EOL ||end of line
|FF ||form feed
|CR ||carriage return
|EOF ||end of file
|ESCAPE ||may be abbreviated ESC
|SPACE ||an alias is BLANK
|RUBOUT ||may be abbreviated RUB
|DELETE ||may be abbreviated DEL
By default, the PSL reader converts upper case alphabetic characters to lower case. This
default is controlled by the value of the switch raise. A value of t indicates that the
conversion should be done. Assuming raise is t, the expression (char a) refers to the
character ”a”. The character ”A” is referenced by (char !A). The ”!” is used as an escape
character, see chapter 12 for more information. The application of lower is said to
modify the character. Lower is not a defined function but it does have the attribute
char-prefix-function on its property list. The value of this property is a function which will
modify the ASCII code of its argument. Modifiers are control and meta (the modifier cntrl
is an abbreviation for control). The following example is a simplified definition of
(defmacro char (u)
(cond ((idp u) (or (get u 'charconst)
((and (pairp u)
(get (first u) 'char-prefix-function))
(list (get (first u) 'char-prefix-function)
(list 'char (second u))))))
Notice that the digits have to be treated as a special case. The PSL reader converts a digit to a
reference to a numeric constant. The definition of the alias space is
(put 'space 'charconst 32)
If the type of the argument to char is not correct then the warning
⋆⋆⋆ Unknown character constant ‘FORM'
is printed and the result will be zero.
The USEFUL package also defines the read macro #. Read macros are explained in detail in
chapter 12. When the reader encounters #, char is applied to the next character. If this
next character is a lower case alphabetic character then it will be converted to upper
case if the switch raise is set to t. If this next character is a read macro then it will
be applied. Such a read macro should return an expression which is acceptable to
1 lisp> #\a
2 lisp> #\‘(a b c)
⋆⋆⋆ Unknown character constant: ‘(BACKQUOTE (A B C))'
Common LISP Functions on Characters
The following functions are available by loading the library module chars.
Common LISP provides a character data type in which every character object has three
attributes: code, bits, and font. The bits attribute allows extra flags to be associated with a
character. The font attribute permits a specification of the style of the glyphs (such as italics).
PSL does not support nonzero bit and font attributes. Because of this, some of the Common
LISP character functions described below have no affect or are not very useful as implemented
in PSL. They are present for compatibility.
An argument to any of the following functions should make use of char or one of the two read
macros #∕ and #\. Since a character in PSL is represented as its ASCII code it is possible to
give a numeric argument to these functions. However, the use of numbers makes the code
difficult to read and much less transportable. The read macro #\ is described in the discussion
of char above. The read macro #/ returns the ASCII code of the next character. In contrast
to #\, the switch raise is ignored and if the next character is a read macro it is not
1 lisp> (eq (char (lower a)) #/a)
2 lisp> (eq (char (lower a)) #\a)
3 lisp> #/‘
4 lisp> #\‘
⋆⋆⋆ Unknown character constant: ‘(BACKQUOTE !^Z)'
(standard-charp C:character): boolean expr
Returns t if the argument is one of the 95 ASCII printing characters.
1 lisp> (standard-charp (char a))
2 lisp> (standard-charp (char (control a)))
(graphicp C:character): boolean expr
Returns t if C is a printable character and nil otherwise. Control and
formatting characters are considered to be not printable. The space character
is a printable character.
(string-charp C:character): boolean expr
Returns t if C is a character that can be an element of a string. Any character
that satisfies standard-charp and graphicp also satisfies string-charp.
(alphap C:character): boolean expr
Returns t if C is an alphabetic character. Liter is an equivalent function.
(uppercasep C:character): boolean expr
Returns t if C is an upper case letter.
(lowercasep C:character): boolean expr
Returns t if C is a lower case letter.
(bothcasep C:character): boolean expr
In PSL this function is the same as alphap.
(digitp C:character): boolean expr
Returns t if C is a digit character (optional radix not supported). An
equivalent function is digit
(alphanumericp C:character): boolean expr
Returns t if C is a digit or an alphabetic.
(char= C1:character C2:character): boolean expr
Returns t if C1 and C2 are the same in all three attributes.
(char-equal C1:character C2:character): boolean expr
Returns t if C1 and C2 are similar. Differences in case, bits, or font are
ignored by this function.
(char< C1:character C2:character): boolean expr
Returns t if C1 is strictly less than C2.
(char> C1:character C2:character): boolean expr
Returns t if C1 is strictly greater than C2.
(char-lessp C1:character C2:character): boolean expr
Like char< but ignores differences in case, fonts, and bits.
(char-greaterp C1:character C2:character): boolean expr
Like char> but ignores differences in case, fonts, and bits.
(char-code C:character): character expr
Returns the code attribute of C. In PSL this function is an identity function.
(char-bits C:character): integer expr
Returns the bits attribute of C, which is always 0 in PSL.
(char-font C:character): integer expr
Returns the font attribute of C, which is always 0 in PSL.
(code-char I:integer): character,nil expr
The purpose of this function is to be able to construct a character by
specifying the code, bits, and font. Because bits and font attributes are not
used in PSL, code-char is an identity function.
(character C:character, string, id): character expr
Attempts to coerce C to be a character. If C is a character, C is returned. If C
is a string, then the first character of the string is returned. If C is a symbol,
the first character of the print name of the symbol is returned. Otherwise an
⋆⋆⋆⋆⋆ ‘FORM' cannot be coerced to a character
(char-upcase C:character): character expr
If (lowercasep C) is true, then char-upcase returns the code of the upper
case of C. Otherwise it returns the code of C.
(char-downcase C:character): character expr
If (uppercasep C) is true, then char-downcase returns the code of the lower
case of C. Otherwise it returns the code of C.
(digit-char N:fixnum): integer expr
If N corresponds to a single digit then the character which represents that
digit is returned. The Common LISP version will accept an optional radix
argument, this function assumes a radix of ten. If N does not correspond to
a single digit then nil is returned.
(char-int C:character): integer expr
Converts character to integer. This is the identity operation in PSL.
(int-char I:integer): character expr
Converts integer to character. This is the identity operation in PSL.