Friday, October 9, 2009

Numbers Characters and Strings In Common Lisp

Note from Practical Common Lisp
It’s also possible to write rationals in bases other than 10. If preceded by #B or #b, a rational literal is read as a binary number with 0 and 1 as the only legal digits. An #O or #o indicates an octal number (legal digits 0–7), and #X or #x indicates hexadecimal (legal digits 0–F or 0–f). You can write rationals in other bases from 2 to 36 with #nR where n is the base (always written in decimal). Additional “digits” beyond 9 are taken from the letters A–Z or a–z.The functions 1+ and 1- provide a shorthand way to express adding and subtracting one from a number. Note that these are different from the macros INCF and DECF. 1+ and 1- are just functions that return a new value, but INCF and DECF modify a place.
The function = is the numeric equality predicate. It compares numbers by mathematical value,ignoring differences in type.
The read syntax for characters objects is simple: #\ followed by the desired character.The case-sensitive analog to the numeric = is the function CHAR=. Like =, CHAR= can take any number of arguments and returns true only if they’re all the same character. The caseinsensitive version is CHAR-EQUAL.
In the string comparison,The arguments—:start1, :end1,:start2, and :end2—specify the starting (inclusive) and ending (exclusive) indices of substrings in the first and second string arguments.


The comparators that return true when their arguments differ—that is, all of them except STRING= and STRING-EQUAL—return the index in the first string where the mismatch was detected.

No comments:

Post a Comment