Booleans, Characters, Strings and Symbols

5.1 Booleans

#t #f #true #false        ; R7RS allows the long forms
(not #f)                  ; #t
(boolean? #f)             ; #t
(if 0 'yes 'no)           ; yes: ONLY #f is false (0, "", and '() are all true)
(boolean=? #t #t)         ; #t

5.2 Characters

#\a #\A #\space #\newline #\tab #\x41 #\λ
(char->integer #\A)       ; 65
(integer->char 955)       ; #\λ
(char-upcase #\a)         ; #\A        (scheme char)
(char-alphabetic? #\a) (char-numeric? #\7) (char-whitespace? #\space)
(digit-value #\7)         ; 7          (scheme char)
(char=? #\a #\a) (char<? #\a #\b) (char-ci=? #\a #\A)

5.3 Strings

(define s "Hello, Scheme")
(string-length s)                     ; 13
(string-ref s 0)                      ; #\H
(substring s 7 13)                    ; "Scheme"
(string-append "foo" "bar")           ; "foobar"
(string-copy s 7)                     ; "Scheme"
(string->list "abc")                  ; (#\a #\b #\c)
(list->string '(#\a #\b))             ; "ab"
(string->symbol "hello")              ; hello
(symbol->string 'hello)               ; "hello"
(string-upcase "scheme")              ; "SCHEME"      (scheme char)
(string=? "a" "a") (string<? "apple" "banana") (string-ci=? "A" "a")
(string-map char-upcase "abc")        ; "ABC"
(string-for-each (lambda (c) (display (char->integer c))) "ab")
(make-string 3 #\x)                   ; "xxx"
(string #\a #\b)                      ; "ab"
(define m (string-copy "hello"))      ; mutable copy (literals are immutable)
(string-set! m 0 #\j)                 ; m = "jello"
(string-fill! m #\z)

5.4 Symbols

'apple                                ; a symbol
(symbol? 'apple)                      ; #t
(eq? 'apple 'apple)                   ; #t: symbols are interned (unique)
(symbol=? 'a 'a 'a)                   ; #t (R7RS)
(string->symbol "with space")         ; |with space|