CSC153, Class 13: Characters and Strings Overview: * Different types * Characters in Scheme * Strings in Scheme * Lab Notes: * Take-home exam Wednesday. Due the following Wednesday. * Yes, I plan to have homework 1 graded by then. * Are there questions on variable-arity procedures? * How many of you know HTML? * Readings for tomorrow: HTML, CGI * All-campus forum, noon ARH 102 ---------------------------------------- Question: How do you document variable-arity procedures ;;; Parameters ;;; required: an integer ;;; optional-1 ... optional-n: 0 or more integers Question: Is there a nice way to display one of the variables? E.g. "You bozo, "hello" is not a number" Answer: Sure, as long as you're willing to try to convert the value to a string. (More info today.) ---------------------------------------- Types in Scheme Consider i. What could it be? * The square root of negative 1. (sqrt -1) 0+i * The name of something. (define i (lambda (x) x)) i * A character: Something that makes up strings Something you can type on the keyboard #\i * A string of length 1 "i" * A symbol 'i Scheme, like most programming languages, necessarily provides different notations (names) for the different kinds of values What can you do with characters and strings in Scheme? * Build new strings from old with string-append (string-append "Hi, " + student) * Build new strings from characters with + (make-string NUM CHAR) + (string CHAR1 CHAR2 CHAR3 ... CHARN) * Build string literals with double quotes * Extract information on strings + A particular character with string-ref + Length with string-length + Substrings with substring (a chunk of the string) * Compare strings More stuff than I want to tell you about. Do the lab. ---------------------------------------- REFLECTION * test, as I've written it, doesn't always give what you'd expect * How did you compare digits to uppercase? (char->integer #\A) (char->integer #\9) or (char