kend@tekchips.LABS.TEK.COM (Ken Dickey) (03/24/90)
Here are a couple of somewhat more efficient versions of a portable string->cannonical-symbol. The only difference is the use of DO vs named LET {some people particularly dislike one or the other}. [Just for fun... or should we discuss style and esthetics for a few weeks? 8^] -Ken Dickey ;;================== (define STRING->CANNONICAL-SYMBOL (let ( (case-squasher (if (eq? 'a (string->symbol "A")) char-upcase char-downcase)) ) (lambda ( <string> ) (let* ( (str-len (string-length <string>)) (decaseified-string (make-string str-len)) ) (let loop ( (index (- str-len 1) ) ) (string-set! decaseified-string index (case-squasher (string-ref <string> index))) (if (> index 0) (loop (- index 1)) (string->symbol decaseified-string)) ) ) ) ) ) ;;================== (define STRING->CANNONICAL-SYMBOL (let ( (case-squasher (if (eq? 'a (string->symbol "A")) char-upcase char-downcase)) ) (lambda ( <string> ) (let* ( (str-len (string-length <string>)) (decaseified-string (make-string str-len)) ) (do ( (index (- str-len 1) (- index 1)) ) ( (< index 0) (string->symbol decaseified-string) ) (string-set! decaseified-string index (case-squasher (string-ref <string> index))) ) ) ) ) )