3 Using Characters and Strings
character. The following changes have been made to string data types to support double-byte characters:
base-stringcorresponds to a string that consists entirely of base characters. If such a string is also a simple string, it is of type
simple-base-string. It is an error to store an extended character in a base string or in a simple base string.
simple-general-stringcorrespond to strings that can contain either base characters or extended characters.
string-charis retained as an extension to Common Lisp. Note that characters with nonzero bits attributes cannot be stored in strings.
If you know that your code uses only base characters, declare strings to be of type
simple-base-string. Base strings use less storage than general strings, and simple base strings use less storage than either simple general strings or base strings.
;; Declare the string argument as a simple base string. (declare (simple-base-string string)) (schar string index))If you need to store extended characters in a string, you should declare strings to be of type
(defun fetch-kanji-char (string index) ;; Declare the string argument as a simple general string. declare (simple-general-string string)) (schar string index))For simple base strings and simple general strings, you can use the functions
sgcharinstead of the Common Lisp function
scharto extract characters. See the reference pages for
sgcharfor complete descriptions of these functions.
;;; This expression compiles to the same code as ;;; FETCH-ASCII-CHAR. (defun fetch-ascii-char-2 (string index) ;; Assume string is always a base string. (sbchar string index))
;;; This expression compiles to the same code as ;;; FETCH-KANJI-CHAR. (defun fetch-kanji-char-2 (string index) ;; Assume string is always a general string. (sgchar string index))
Generated with Harlequin WebMaker