Characters.html (9470B)
1 <html lang="en"> 2 <head> 3 <title>Characters - klisp Reference Manual</title> 4 <meta http-equiv="Content-Type" content="text/html"> 5 <meta name="description" content="klisp Reference Manual"> 6 <meta name="generator" content="makeinfo 4.13"> 7 <link title="Top" rel="start" href="index.html#Top"> 8 <link rel="prev" href="Strings.html#Strings" title="Strings"> 9 <link rel="next" href="Ports.html#Ports" title="Ports"> 10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11 <meta http-equiv="Content-Style-Type" content="text/css"> 12 <style type="text/css"><!-- 13 pre.display { font-family:inherit } 14 pre.format { font-family:inherit } 15 pre.smalldisplay { font-family:inherit; font-size:smaller } 16 pre.smallformat { font-family:inherit; font-size:smaller } 17 pre.smallexample { font-size:smaller } 18 pre.smalllisp { font-size:smaller } 19 span.sc { font-variant:small-caps } 20 span.roman { font-family:serif; font-weight:normal; } 21 span.sansserif { font-family:sans-serif; font-weight:normal; } 22 --></style> 23 <link rel="stylesheet" type="text/css" href="css/style.css"> 24 </head> 25 <body> 26 <div class="node"> 27 <a name="Characters"></a> 28 <p> 29 Next: <a rel="next" accesskey="n" href="Ports.html#Ports">Ports</a>, 30 Previous: <a rel="previous" accesskey="p" href="Strings.html#Strings">Strings</a>, 31 Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 32 <hr> 33 </div> 34 35 <!-- node-name, next, previous, up --> 36 <h2 class="chapter">16 Characters</h2> 37 38 <p><a name="index-characters-266"></a> 39 A character is an object that represents an ASCII character (for 40 now, only ASCII is supported in klisp, in the future, full UNICODE 41 will be supported). 42 43 <p>The external representation of characters consists of a leading “#\” 44 and the character or character name or “#\x” followed by the hex 45 unicode code point (only ASCII supported for now). The supported 46 names for now are “null”, “alarm”, “backspace”, “tab”, 47 “newline”, “return”, “escape”, “space”, “delete”, “vtab”, 48 and “formfeed” (this is a combination of the ones accepted in r6rs 49 and r7rs). 50 51 <p>Characters are immutable. The character type is encapsulated. 52 53 <p>SOURCE NOTE: This section is still missing from the report. The 54 features defined here were taken mostly from r7rs. 55 56 <div class="defun"> 57 — Applicative: <b>char?</b> (<var>char? . objects</var>)<var><a name="index-char_003f-267"></a></var><br> 58 <blockquote><p> The primitive type predicate for type character. <code>char?</code> 59 returns true iff all the objects in <code>objects</code> are of type 60 character. 61 </p></blockquote></div> 62 63 <div class="defun"> 64 — Applicative: <b>char=?</b> (<var>char=? . chars</var>)<var><a name="index-char_003d_003f-268"></a></var><br> 65 — Applicative: <b>char<?</b> (<var>char<? . chars</var>)<var><a name="index-char_003c_003f-269"></a></var><br> 66 — Applicative: <b>char<=?</b> (<var>char<=? . chars</var>)<var><a name="index-char_003c_003d_003f-270"></a></var><br> 67 — Applicative: <b>char>?</b> (<var>char>? . chars</var>)<var><a name="index-char_003e_003f-271"></a></var><br> 68 — Applicative: <b>char>=?</b> (<var>char>=? . chars</var>)<var><a name="index-char_003e_003d_003f-272"></a></var><br> 69 <blockquote><p> These predicates compare any number of characters using their 70 ASCII value for the comparison. 71 </p></blockquote></div> 72 73 <div class="defun"> 74 — Applicative: <b>char-ci=?</b> (<var>char-ci=? . chars</var>)<var><a name="index-char_002dci_003d_003f-273"></a></var><br> 75 — Applicative: <b>char-ci<?</b> (<var>char-ci<? . chars</var>)<var><a name="index-char_002dci_003c_003f-274"></a></var><br> 76 — Applicative: <b>char-ci<=?</b> (<var>char-ci<=? . chars</var>)<var><a name="index-char_002dci_003c_003d_003f-275"></a></var><br> 77 — Applicative: <b>char-ci>?</b> (<var>char-ci>? . chars</var>)<var><a name="index-char_002dci_003e_003f-276"></a></var><br> 78 — Applicative: <b>char-ci>=?</b> (<var>char-ci>=? . chars</var>)<var><a name="index-char_002dci_003e_003d_003f-277"></a></var><br> 79 <blockquote><p> These predicates convert the chars to lowercase and then compare 80 their ASCII values. 81 </p></blockquote></div> 82 83 <div class="defun"> 84 — Applicative: <b>char-alphabetic?</b> (<var>char-alphabetic? . chars</var>)<var><a name="index-char_002dalphabetic_003f-278"></a></var><br> 85 — Applicative: <b>char-numeric?</b> (<var>char-numeric? . chars</var>)<var><a name="index-char_002dnumeric_003f-279"></a></var><br> 86 — Applicative: <b>char-whitespace?</b> (<var>char-whitespace? . chars</var>)<var><a name="index-char_002dwhitespace_003f-280"></a></var><br> 87 <blockquote><p> These predicates return true iff all of their arguments are 88 respectively “alphabetic”, “numeric”, or “whitespace”. 89 </p></blockquote></div> 90 91 <div class="defun"> 92 — Applicative: <b>char-upper-case?</b> (<var>char-upper-case? . chars</var>)<var><a name="index-char_002dupper_002dcase_003f-281"></a></var><br> 93 — Applicative: <b>char-lower-case?</b> (<var>char-lower-case? . chars</var>)<var><a name="index-char_002dlower_002dcase_003f-282"></a></var><br> 94 — Applicative: <b>char-title-case?</b> (<var>char-title-case? . chars</var>)<var><a name="index-char_002dtitle_002dcase_003f-283"></a></var><br> 95 <blockquote><p>These predicates return true iff all of their arguments are 96 respectively “upper case, “lower case”, or “title case”. 97 98 <p>Currently klisp only supports ASCII, so there are no title-cased 99 characters (i.e. <code>char-title-case?</code> always returns false). 100 </p></blockquote></div> 101 102 <div class="defun"> 103 — Applicative: <b>char-upcase</b> (<var>char-upcase char</var>)<var><a name="index-char_002dupcase-284"></a></var><br> 104 — Applicative: <b>char-downcase</b> (<var>char-downcase char</var>)<var><a name="index-char_002ddowncase-285"></a></var><br> 105 — Applicative: <b>char-titlecase</b> (<var>char-downcase char</var>)<var><a name="index-char_002dtitlecase-286"></a></var><br> 106 — Applicative: <b>char-foldcase</b> (<var>char-downcase char</var>)<var><a name="index-char_002dfoldcase-287"></a></var><br> 107 <blockquote><p>These applicatives return a character <code>char2</code> so that: 108 <pre class="example"> (char-ci=? char char2) ⇒ #t 109 </pre> 110 <p>If <code>char</code> is alphabetic then the following holds: 111 112 <pre class="example"> (char-upper-case? (char-upcase char)) ⇒ #t 113 (char-lower-case? (char-downcase char)) ⇒ #t 114 </pre> 115 <p>Currently klisp only supports ASCII, so <code>char-foldcase</code> behaves 116 as <code>char-downcase</code> and <code>char-titlecase</code> behaves as 117 <code>char-upcase</code>. 118 </p></blockquote></div> 119 120 <div class="defun"> 121 — Applicative: <b>char->integer</b> (<var>char->integer char</var>)<var><a name="index-char_002d_003einteger-288"></a></var><br> 122 — Applicative: <b>integer->char</b> (<var>integer->char k</var>)<var><a name="index-integer_002d_003echar-289"></a></var><br> 123 <blockquote><p> These applicatives convert between ASCII values (as exact integers 124 between 0 and 127) and characters. If an integer that is out of range 125 for ASCII characters is passed to <code>integer->char</code>, an error is 126 signaled. 127 </p></blockquote></div> 128 129 <div class="defun"> 130 — Applicative: <b>char-digit?</b> (<var>char-digit? char </var>[<var>base</var>])<var><a name="index-char_002ddigit_003f-290"></a></var><br> 131 <blockquote><p><code>base</code> must be an exact integer, between 2 and 36, it omitted it 132 defaults to <code>10</code>. 133 134 <p>Applicative <code>char-digit?</code> is a predicate that returns true iff 135 <code>char</code> is a digit in base <code>base</code>. If <code>base</code> is greater 136 than 10, then either upper case or lower case letters can be used. 137 138 <p>SOURCE NOTE: This is like char-numeric? but with bases other than 10. 139 </p></blockquote></div> 140 141 <div class="defun"> 142 — Applicative: <b>char->digit</b> (<var>char->digit char </var>[<var>base</var>])<var><a name="index-char_002d_003edigit-291"></a></var><br> 143 — Applicative: <b>digit->char</b> (<var>digit->char digit </var>[<var>base</var>])<var><a name="index-digit_002d_003echar-292"></a></var><br> 144 <blockquote><p><code>base</code> must be an exact integer, between 2 and 36, it omitted it 145 defaults to <code>10</code>. In <code>char->digit</code>, <code>char</code> should be a 146 character such that 147 <pre class="example"> (char-digit? char base) ⇒ #t 148 </pre> 149 <p>In <code>digit->char</code>, <code>digit</code> should be an exact integer such 150 that 151 <pre class="example"> (>=? (- base 1) digit 0) ⇒ #t 152 </pre> 153 <p>These two applicatives convert between chars representing digits and 154 the corresponding integer values, in arbitrary bases (between 2 and 155 36). 156 157 <p><code>char->digit</code> accepts either lower or upper case characters (if 158 the base is greater than 10), <code>digit->char</code> always returns 159 lower characters (or numbers of course). 160 161 <p>SOURCE NOTE: These are like r7rs digit-value but augmented with a 162 base argument. 163 </p></blockquote></div> 164 165 <!-- *-texinfo-*- --> 166 </body></html> 167