NOTE: When pasting, paste one line at a time.
From chapter 1 of scheme tutorial (just present it):

; starts a sequence.

begin introduces a sequence of "subforms" (like statements).
display outputs its string argument.

Interpreter: reads-evals-prints.

You can also load a file.

display is a "side-effect". Not the result of an evaluation.

Chapter 2.
#t
#f 
are booleans.

Functions that are named and evaluate to booleans end in ?.

+, -, *, /, expt

max, min

(char? #\c) =>  #t

Symbols are variable names unless they are quoted.
Anything is a symbol unless it is a number, boolean
or a list.

(symbol? 'xyz) =>  #t
(symbol? 42)   =>  #f

(define x "hello there sapphire")

set! changes a value that already exists though define works too.

(define x "bye") gives an error.
(set! x "byebye")

strings are sequences of characters.
symbols have values that have a sequence of characters as their name.

(string #\h #\e #\l #\l #\o)
=>  "hello"

(define greeting "Hello; Hello!")
> (string-ref greeting 1)
#\e

> (define y (string-append greeting "bye"))
> y
"Hello; Hello!bye"


Scheme as a descendent of lisp is about lists:

dotted pair: compound made by combining two arbitrary values
into an ordered sequence.

(define x (cons 'alice 'bob))

(car x)
(cdr x) ==> returns the second element.

(define y (list 'bob 'ted 'carol 'alice))

> (car y)
bob
> (cdr y)
(ted carol alice)


> (list-ref y 1)
ted


pair?, list?, and null? 

(define mylist '( this course is great))

(car mylist) ; first element just this

(cdr mylist) ; everything but the first element.

(cons (cdr mylist) (car mylist))
(cons (cdr mylist) (cdr mylist))
(cons (car mylist) (car mylist))




Chapter 3: forms (a program or a fragment of a program)


(define add2 (lambda (x) (+ x 2)))

(define area (lambda (length breadth) (* length breadth)))


(define area *) ; substitute * for area and you get the right answer.


Chapter 4: conditionals. Emphasize cond.

(define rev (lambda (x)
   (cond ((null? x) x)
     (else (cons (rev (cdr x)) (list (car x))))
   )
  )
)
(load "examp.scm")

; here are the functions:

(define rev (lambda (x)
   (cond ((null? x) x)
     (else (cons (rev (cdr x)) (list (car x))))
   )
  )
)

(define is-even?
  (lambda (n)
    (if (= n 0) #t
        (is-odd? (- n 1)))))

(define is-odd?
  (lambda (n)
    (if (= n 0) #f
        (is-even? (- n 1)))))


(let countdown ((i 10))
  (if (= i 0) 'liftoff
      (begin
        (display i)
        (newline)
        (countdown (- i 1)))))


(define myreverse!
  (lambda (s)
    (let loop ((s s) (r '()))
      (if (null? s) r
	  (let ((d (cdr s)))
            (set-cdr! s r)
	    (loop d s))))))



(rev (list 1 2 3 4))

Chapter 5: scoping

locals are well-behaved.
They neither take their values from globals outside nor do they
change those outside values.

Ability to define locals outside a procedure using let.


Chapter 6: Mapping a procedure across a list

(map add2 '(1 2 3))

for-each is similar but returns void.

(map cons '(1 2 3) '(10 20 30))
=>  ((1 . 10) (2 . 20) (3 . 30))

(let ((x 1)
      (y 2)
      (z 3))
  (list x y z))

As with lambda, within the let-body, 
the local x (bound to 1) shadows the global x

(let countdown ((i 10))
  (if (= i 0) 'liftoff
      (begin
        (display i)
        (newline)
        (countdown (- i 1)))))

So we are assigning 10 to i and then performing the if statement.
That if statement in turn has side effects and then invokes this loop,
BUT WITH A NEW INITIALIZATION.

(define reverse!
  (lambda (s)
    (let loop ((s s) (r '()))
      (if (null? s) r
	  (let ((d (cdr s)))
            (set-cdr! s r)
	    (loop d s))))))


Let's look at this one slowly:

(define s '(1 2 3))
(define r '())

> s
(1 2 3)

> r
()

In the first instance of the loop, we will get:
(define d (cdr s))


> d
(2 3)

(set-cdr! s r) ; have eliminated the cdr of s.
> s
(1)

Now we go through the loop again.
Now, what we called s before is d and what we called r before
is the value s. 

(define r s)
(define s d)

> r
(1)
> s
(2 3)

 (define d (cdr s))
> d
(3)

(set-cdr! s r)
> s
(2 1)

Now we go through the loop again.
Again, what we called s before is d and what we called r before
is the value s.

(define r s)
(define s d)
> r
(2 1)
> s
(3)

Again the null? test is not met so 
(define d (cdr s))
> d
()

(set-cdr! s r)
> s
(3 2 1)

Next time through the loop, r will have the value (3 2 1) and 
s will have the value () so the reverse will be returned.

Invariant: In the ith iteration of the loop where i starts at 0,
the first i members of the original list are held in reverse order in r.
s has the remaining elements of the original list in their original order.
The first part of this holds because (set-cdr! s r)
is list consisting of the ith element of the original list followed by
the reverse of elements 0 to i-1 of the original list.
That is the reverse of elements 0 to i of the original list.
d in turn contains the remaining elements of the original list (starting
at location i+1).


Chapter 7:

Intelligent input/output

read-char reads the next character
read-line reads the next line, 
read reads the next s-expression

Chapter 8: optional.

Chapter 9: optional

Chapter 10: Association lists.

((a . 1) (b . 2) (c . 3))

There is also the more sophisticated table, but that's optional.

Doesn't seem to work.

Chapter 11: on your own.

Chapter 12: class and instances of a class.
The instances are called objects.
Each object (instance) has slots (members??
or attributes in C++ terminology).
Also methods.
Inherit slots and methods of superclass but no overloading.

Can have multiple inheritance.
Otherwise on your own.