characters.texi (4930B)
1 @c -*-texinfo-*- 2 @setfilename ../src/characters 3 4 @node Characters, Ports, Strings, Top 5 @comment node-name, next, previous, up 6 7 @chapter Characters 8 @cindex characters 9 10 A character is an object that represents an ASCII character (for 11 now, only ASCII is supported in klisp, in the future, full UNICODE 12 will be supported). 13 14 The external representation of characters consists of a leading ``#\'' 15 and the character or character name or ``#\x'' followed by the hex 16 unicode code point (only ASCII supported for now). The supported 17 names for now are ``null'', ``alarm'', ``backspace'', ``tab'', 18 ``newline'', ``return'', ``escape'', ``space'', ``delete'', ``vtab'', 19 and ``formfeed'' (this is a combination of the ones accepted in r6rs 20 and r7rs). 21 22 Characters are immutable. The character type is encapsulated. 23 24 SOURCE NOTE: This section is still missing from the report. The 25 features defined here were taken mostly from r7rs. 26 27 @deffn Applicative char? (char? . objects) 28 The primitive type predicate for type character. @code{char?} 29 returns true iff all the objects in @code{objects} are of type 30 character. 31 @end deffn 32 33 @deffn Applicative char=? (char=? . chars) 34 @deffnx Applicative char<? (char<? . chars) 35 @deffnx Applicative char<=? (char<=? . chars) 36 @deffnx Applicative char>? (char>? . chars) 37 @deffnx Applicative char>=? (char>=? . chars) 38 These predicates compare any number of characters using their 39 ASCII value for the comparison. 40 @end deffn 41 42 @deffn Applicative char-ci=? (char-ci=? . chars) 43 @deffnx Applicative char-ci<? (char-ci<? . chars) 44 @deffnx Applicative char-ci<=? (char-ci<=? . chars) 45 @deffnx Applicative char-ci>? (char-ci>? . chars) 46 @deffnx Applicative char-ci>=? (char-ci>=? . chars) 47 These predicates convert the chars to lowercase and then compare 48 their ASCII values. 49 @end deffn 50 51 @deffn Applicative char-alphabetic? (char-alphabetic? . chars) 52 @deffnx Applicative char-numeric? (char-numeric? . chars) 53 @deffnx Applicative char-whitespace? (char-whitespace? . chars) 54 These predicates return true iff all of their arguments are 55 respectively ``alphabetic'', ``numeric'', or ``whitespace''. 56 @end deffn 57 58 @deffn Applicative char-upper-case? (char-upper-case? . chars) 59 @deffnx Applicative char-lower-case? (char-lower-case? . chars) 60 @deffnx Applicative char-title-case? (char-title-case? . chars) 61 These predicates return true iff all of their arguments are 62 respectively ``upper case, ``lower case'', or ``title case''. 63 64 Currently klisp only supports ASCII, so there are no title-cased 65 characters (i.e. @code{char-title-case?} always returns false). 66 @end deffn 67 68 @deffn Applicative char-upcase (char-upcase char) 69 @deffnx Applicative char-downcase (char-downcase char) 70 @deffnx Applicative char-titlecase (char-downcase char) 71 @deffnx Applicative char-foldcase (char-downcase char) 72 These applicatives return a character @code{char2} so that: 73 @example 74 (char-ci=? char char2) @result{} #t 75 @end example 76 77 If @code{char} is alphabetic then the following holds: 78 79 @example 80 (char-upper-case? (char-upcase char)) @result{} #t 81 (char-lower-case? (char-downcase char)) @result{} #t 82 @end example 83 84 Currently klisp only supports ASCII, so @code{char-foldcase} behaves 85 as @code{char-downcase} and @code{char-titlecase} behaves as 86 @code{char-upcase}. 87 @end deffn 88 89 @deffn Applicative char->integer (char->integer char) 90 @deffnx Applicative integer->char (integer->char k) 91 These applicatives convert between ASCII values (as exact integers 92 between 0 and 127) and characters. If an integer that is out of range 93 for ASCII characters is passed to @code{integer->char}, an error is 94 signaled. 95 @end deffn 96 97 @deffn Applicative char-digit? (char-digit? char [base]) 98 @code{base} must be an exact integer, between 2 and 36, it omitted it 99 defaults to @code{10}. 100 101 Applicative @code{char-digit?} is a predicate that returns true iff 102 @code{char} is a digit in base @code{base}. If @code{base} is greater 103 than 10, then either upper case or lower case letters can be used. 104 105 SOURCE NOTE: This is like char-numeric? but with bases other than 10. 106 @end deffn 107 108 @deffn Applicative char->digit (char->digit char [base]) 109 @deffnx Applicative digit->char (digit->char digit [base]) 110 @code{base} must be an exact integer, between 2 and 36, it omitted it 111 defaults to @code{10}. In @code{char->digit}, @code{char} should be a 112 character such that 113 @example 114 (char-digit? char base) @result{} #t 115 @end example 116 In @code{digit->char}, @code{digit} should be an exact integer such 117 that 118 @example 119 (>=? (- base 1) digit 0) @result{} #t 120 @end example 121 122 These two applicatives convert between chars representing digits and 123 the corresponding integer values, in arbitrary bases (between 2 and 124 36). 125 126 @code{char->digit} accepts either lower or upper case characters (if 127 the base is greater than 10), @code{digit->char} always returns 128 lower characters (or numbers of course). 129 130 SOURCE NOTE: These are like r7rs digit-value but augmented with a 131 base argument. 132 @end deffn