; Strings ; you can think of strings as a special type of list of characters ; we can have a null string, "" ; we can pick out any character from a string, using STRING-REF ; strings are different from lists in that, you cannot use list operations on them ; and strings only consist of characters ; suppose that we want to write procedures to operate on strings as if ; they were lists, how can we write STRING-CAR, STRING-CDR, STRING-CONS? ; string-null? returns #t if input string is "" (define string-null? (lambda (str) (equal? str ""))) ; string-car returns the first character of a string (define string-car (lambda (str) (string-ref str 0))) ; string-cdr returns the input string with the first character removed (define string-cdr (lambda (str) (substring str 1 (string-length str)))) ; string-cons takes in a character and a string and puts that character on the ; front of the string (define string-cons (lambda (char str) (string-append (string char) str))) ; count-this-char takes in a character and a string and counts the number ; of occurences of that character in that string (define count-this-char (lambda (char str) (if (string-null? str) 0 (if (equal? char (string-car str)) (+ 1 (count-this-char char (string-cdr str))) (count-this-char char (string-cdr str))))))