\section{Strings} A string is a sequence of characters. This module implements finite-length strings, for use in documentation and naming things using Max. We don't have a sequence type yet, so there's no way to access the individual characters. You'll have to start with a LISP string for now. <>= <> <> <> @ <>= (in-package max) @ \subsection{Implementation} As you would expect, there's a new max type for strings, a new class implementing that type, a new method specializing ADDR-VALUE-EQUAL, and a helper function to return a string address. Actually it's the only way to return a string address at present. <>= <> <> <> <> <> @ Make a new class for the type of finite-length strings. There are an infinite number of such strings, so the type has an infinite number of values. We implement Max strings by storing the LISP string directly in the value field of the string address. Make no statement as to the characters that can be in these strings; just use whatever LISP strings are. <>= (defclass string-type (max-type) nil) @ <>= (defparameter *string-type* (make-type :class 'string-type :key 'string) ) (add-init-hook #'(lambda () (add-name *string-type* "strings"))) @ <>= (defmethod addr-value-equal ((s string-type) a b) (equal a b) ) @ Return the max string corresponding to an optional LISP string. If a LISP string is not supplied, return the empty max string. <>= (defun make-string-address (&optional (str "")) (make-address-form (addr-value *string-type*) str) ) @ For use in the LISP environment: <>= (defun print-string (str) (format t "~a~a~a" #\" (addr-value str) #\") ) @ \subsection{Operations on strings} There are so few of these they don't even get their own chunk. Concatenate two Max strings and return another one. <>= (defun string-concatenate (str1 str2) (make-string-address (concatenate 'string (cdr str1) (cdr str2))) ) (add-init-hook #'(lambda () (let ((string-concatenate (make-function 'builtin-function (type-product *string-type* *string-type*) *string-type* #'(lambda (twostrings) (apply #'string-concatenate (product-values twostrings)) )) )) (add-public-function string-concatenate) (add-name string-concatenate "concatenate") ) ))