CS151, Class 12: Strings Overview: * Characters in Scheme * Strings in Scheme * Lab Notes: * Concerns about time in class. * Are there questions on Booleans and conditionals? * Are there questions on the writeup? Questions on Homework * .ss or .scm I DONT CARE * Distinguishing between rationals and reals We'll say that rationals are exact and reals are inexact (if (and (rational? val) (exact? val)) 'looks-like-a-rational-to-me 'looks-like-something-else) * Why does (and num1 num2 ... num3) return num3 ---------------------------------------- There are many different possible interpretations of i * Variable i, naming some other value (define i 5) (define i (list 5)) * Atomic symbol i, reprsenting some concept (e.g., self) 'i * The letter you can type on the keyboard, representing part of a word #\i * An i can be the imaginary part of a complex number 0+i * Variation of variable: Can be an argument (define foo (lambda (i) ...)) * One of the other kinds of i, as part of a list (list i) or (list 'i) or (list 0+i) or (list #\i) * The one-letter word i Sam tries to resolve confusion by swtiching to "cat" * 'cat - an abstract concept * cat - names some value or names some function * "cat" - the sequence of letters #\c #\a #\t In most languages, it is helpful to be able to speak about both sequences of characters (which we call strings) and single characters In Scheme, single characters start with #\, strings are surrounded by double quotation marks #\a "Sam" What can you do with characters and strings? * Compare them to each other Perry Rebelsky Cook Stoltzfus * Build strings + From characters (string #\a #\b #\c) -> "abc" + From other strings (define student-to-pick-on "Andy") (string-append student-to-pick-on ", is this clear?") -> "Andy, is this clear?" Can you use string append on characters? No! (string-append "student" (string #\s)) (string-append "student" "s") -> "students" The following is illegal and is retained in the eboard only fior discussion purposes. (string-append ("student") (string #\s)) * Get information about strings: string-length substring etc. Do the lab WARNING control-char? should take a character as a parameter!