Next: , Previous: , Up: Standards   [Contents][Index]

2.11 Characters

ECL is fully ANSI Common-Lisp compliant in all aspects of the character data type, with the following peculiarities.

Next: , Up: Characters   [Contents][Index]

2.11.1 Unicode vs. POSIX locale

There are two ways of building ECL: with C or with Unicode character codes. These build modes are accessed using the --disable-unicode and --enable-unicode configuration options, the last one being the default.

When using C characters we are actually relying on the char type of the C language, using the C library functions for tasks such as character conversions, comparison, etc. In this case characters are typically 8 bit wide and the character order and collation are determines by the current POSIX or C locale. This is not very accurate, leaves out many languages and character encodings but it is sufficient for small applications that do not need multilingual support.

When no option is specified ECL builds with support for a larger character set, the Unicode 6.0 standard. This uses 24 bit large character codes, also known as codepoints, with a large database of character properties which include their nature (alphanumeric, numeric, etc), their case, their collation properties, whether they are standalone or composing characters, etc. Character types

If ECL is compiled without Unicode support, all characters are implemented using 8-bit codes and the type extended-char is empty. If compiled with Unicode support, characters are implemented using 24 bits and the extended-char type covers characters above code 255.

TypeWith UnicodeWithout Unicode
extended-char-256-16777215 Character names

All characters have a name. For non-printing characters between 0 and 32, and for 127 we use the ordinary ASCII names. Characters above 127 are printed and read using hexadecimal Unicode notation, with a U followed by 24 bit hexadecimal number, as in U0126.


Table 2.6

Note that #\Linefeed is synonymous with #\Newline and thus is a member of standard-char.

Next: , Previous: , Up: Characters   [Contents][Index]

2.11.2 #\Newline characters

Internally, ECL represents the #\Newline character by a single code. However, when using external formats, ECL may parse character pairs as a single #\Newline, and vice versa, use multiple characters to represent a single #\Newline, see Streams - External formats.

Previous: , Up: Characters   [Contents][Index]

2.11.3 C Reference C types

C character types

Type names



ECL defines two C types to hold its characters: ecl_base_char and ecl_character.

For your code to be portable and future proof, use both types to really express what you intend to do. Constructors

Creating and extracting characters from Lisp objects


Macro: cl_object ECL_CODE_CHAR (ecl_character code);
Macro: ecl_character ECL_CHAR_CODE (cl_object o);
Function: ecl_character ecl_char_code (cl_object o);
Function: ecl_base_char ecl_base_char_code (cl_object o);


These functions and macros convert back and forth from C character types to Lisp. The macros ECL_CHAR_CODE and ECL_CODE_CHAR perform this coercion without checking the arguments. The functions ecl_char_code and ecl_base_char_code, on the other hand, verify that the argument has the right type and signal an error otherwise. Predicates

C predicates for Lisp characters


Function: bool ecl_base_char_p (ecl_character c);
Function: bool ecl_alpha_char_p (ecl_character c);
Function: bool ecl_alphanumericp (ecl_character c);
Function: bool ecl_graphic_char_p (ecl_character c);
Function: bool ecl_digitp (ecl_character c);
Function: bool ecl_standard_char_p (ecl_character c);


These functions are equivalent to their Lisp equivalents but return C booleans. Character case

C functions related to the character case


Function: bool ecl_upper_case_p (ecl_character c);
Function: bool ecl_lower_case_p (ecl_character c);
Function: bool ecl_both_case_p (ecl_character c);
Function: ecl_character ecl_char_downcase (ecl_character c);
Function: ecl_character ecl_char_upcase (ecl_character c);


These functions check or change the case of a character. Note that in a Unicode context, the output of these functions might not be accurate (for instance when the uppercase character has two or more codepoints). ANSI Dictionary

Common Lisp and C equivalence

Lisp symbolC function
char=cl_object cl_charE(cl_narg narg, ...)
char/=cl_object cl_charNE(cl_narg narg, ...)
char<cl_object cl_charL(cl_narg narg, ...)
char>cl_object cl_charG(cl_narg narg, ...)
char<=cl_object cl_charLE(cl_narg narg, ...)
char>=cl_object cl_charGE(cl_narg narg, ...)
char-equalcl_object cl_char_equal(cl_narg narg, ...)
char-not-equalcl_object cl_char_not_equal(cl_narg narg, ...)
char-lesspcl_object cl_char_lessp(cl_narg narg, ...)
char-greaterpcl_object cl_char_greaterp(cl_narg narg, ...)
char-not-greaterpcl_object cl_char_not_greaterp(cl_narg narg, ...)
char-not-lesspcl_object cl_char_not_lessp(cl_narg narg, ...)
charactercl_object cl_character(cl_object char_designator)
characterpcl_object cl_characterp(cl_object object)
alpha-char-pcl_object cl_alpha_char_p(cl_object character)
alphanumericpcl_object cl_alphanumericp(cl_object character)
digit-charcl_object cl_digit_char(cl_narg narg, cl_object character, ...)
digit-char-pcl_object cl_digit_char_p(cl_narg narg, cl_object character, ...)
graphic-char-pcl_object cl_graphic_char_p(cl_object character)
standard-char-pcl_object cl_standard_char_p(cl_object character)
char_upcasecl_object cl_char_upcase(cl_object character)
char-downcasecl_object cl_char_downcase(cl_object character)
upper-case-pcl_object cl_upper_case_p(cl_object character)
lower-case-pcl_object cl_lower_case_p(cl_object character)
both-case-pcl_object cl_both_case_p(cl_object character)
char-codecl_object cl_char_code(cl_object character)
char-intcl_object cl_char_int(cl_object character)
code-charcl_object cl_code_char(cl_object code)
char-namecl_object cl_char_name(cl_object character)
name-charcl_object cl_name_char(cl_object name)

Previous: , Up: Characters   [Contents][Index]