User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:char-upcase [2019/09/14 05:00]
cl:functions:char-upcase [2019/09/22 06:00] (current)
Line 1: Line 1:
 +====== Function CHAR-UPCASE,​ CHAR-DOWNCASE ======
 +
 +====Syntax====
 +  * **char-upcase** //​character//​ → //​corresponding-character//​
 +  * **char-downcase** //​character//​ → //​corresponding-character//​
 +
 +====Arguments and Values====
 +  * //​character//,​ //​corresponding-character//​ - a //​[[CL:​Glossary:​character]]//​.
 +
 +====Description====
 +If //​character//​ is a //​[[CL:​Glossary:​lowercase]]//​ //​[[CL:​Glossary:​character]]//,​ **char-upcase** returns the corresponding //​[[CL:​Glossary:​uppercase]]//​ //​[[CL:​Glossary:​character]]//​. Otherwise, **char-upcase** just returns the given //​character//​.
 +
 +If //​character//​ is an //​[[CL:​Glossary:​uppercase]]//​ //​[[CL:​Glossary:​character]]//,​ **char-downcase** returns the corresponding //​[[CL:​Glossary:​lowercase]]//​ //​[[CL:​Glossary:​character]]//​. Otherwise, **char-downcase** just returns the given //​character//​.
 +
 +The result only ever differs from //​character//​ in its //​[[CL:​Glossary:​code]]//​ //​[[CL:​Glossary:​attribute]]//;​ all //​[[CL:​Glossary:​implementation-defined]]//​ //​[[CL:​Glossary:​attribute|attributes]]//​ are preserved.
 +
 +====Examples====
 +
 +<​blockquote> ​
 +(char-upcase #\a) <​r>#​\A </r>
 +(char-upcase #\A) <​r>#​\A </r>
 +(char-downcase #\a) <​r>#​\a </r>
 +(char-downcase #\A) <​r>#​\a </r>
 +(char-upcase #\9) <​r>#​\9 </r>
 +(char-downcase #\9) <​r>#​\9 </r>
 +(char-upcase #\@) <​r>#​\@ </r>
 +(char-downcase #\@) <​r>#​\@ </r>
 +</​blockquote>​
 +Note that this next example might run for a very long time in some //​[[CL:​Glossary:​implementation|implementations]]//​ if **[[CL:​Constant Variables:​char-code-limit]]** happens to be very large for that //​[[CL:​Glossary:​implementation]]//​.
 +<​blockquote> ​
 +([[CL:​Macros:​dotimes]] (code [[CL:​Constant Variables:​char-code-limit]])
 +  ([[CL:​Special Operators:​let]] ((char ([[CL:​Functions:​code-char]] code)))
 +    ([[CL:​Macros:​when]] char
 +      ([[CL:​Macros:​unless]] ([[CL:​Macros:​cond]] (([[CL:​Functions:​upper-case-p]] char) 
 +                     ​([[CL:​Functions:​char-equal|char=]] (char-upcase (char-downcase char)) char))
 +                    (([[CL:​Functions:​lower-case-p]] char) 
 +                     ​([[CL:​Functions:​char-equal|char=]] (char-downcase (char-upcase char)) char))
 +                    ([[CL:​Constant Variables:​t]] ​
 +                     ​([[CL:​Macros:​and]] ([[CL:​Functions:​char-equal|char=]] (char-upcase (char-downcase char)) char) 
 +                          ([[CL:​Functions:​char-equal|char=]] (char-downcase (char-upcase char)) char)))) ​
 +        ([[CL:​Macros:​return]] char))))) <​r>​[[CL:​Constant Variables:​nil|NIL]] ;; TODO fix, does not return NIL on SBCL, ECL or CMUCL</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +Should signal an error of type type-error if //​character//​ is not a //​[[CL:​Glossary:​character]]//​.
 +
 +====See Also====
 +
 +**[[CL:​Functions:​upper-case-p|Function UPPER-CASE-P]]**,​ **[[CL:​Functions:​alpha-char-p|Function ALPHA-CHAR-P]]**,​ {\secref\CharactersWithCase},​ {\secref\ImplementationDefinedScripts}
 +
 +====Notes====
 +If the //​corresponding-char//​ is //​[[CL:​Glossary:​different]]//​ than //​character//,​ then both the //​character//​ and the //​corresponding-char//​ have //​[[CL:​Glossary:​case]]//​.
 +
 +Since **[[CL:​Functions:​char-equal]]** ignores the //​[[CL:​Glossary:​case]]//​ of the //​[[CL:​Glossary:​character|characters]]//​ it compares, the //​corresponding-character//​ is always the //​[[CL:​Glossary:​same]]//​ as //​character//​ under **[[CL:​Functions:​char-equal]]**.
 +
 +\issue{CHARACTER-PROPOSAL:​2-1-1}