3 Using Characters and Strings

3.2 Strings

In Common Lisp, a string is a vector whose elements are of typecharacter. The following changes have been made to string data types to support double-byte characters:

If you do not modify your code in this release, strings can contain either base characters or extended characters. Your code will work as before, but string operations might be slower. To get the most efficient performance from your code, you must now explicitly declare the types of strings.

If you know that your code uses only base characters, declare strings to be of typebase-string orsimple-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 typegeneral-string orsimple-general-string.

(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 functionssbchar andsgchar instead of the Common Lisp functionschar to extract characters. See the reference pages for sbchar and sgchar for 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))

3.2.1 - New string operations
3.2.2 - Changes to Common Lisp string operations

International Character Sets - 9 SEP 1996

Generated with Harlequin WebMaker