We're looking at the material in chapter 3, on "state".
Today we'll discuss the ideas in 3.1, then leave the 2nd half of the class for an SEPC discussion.
There's no class next Thursday - it's a plan day - so there won't be a written assignment due next week. (But there may be a longer one the week after.)
I'm going to try something a bit different today , in the spirit of "more thinking by you" and "less talking by me". We'll try to do some exercises together, with me as the "type some stuff" and you telling me what to type or try.
And we'll study the sections in the text together, with pauses as needed.
Let's continue our walk through 3.1, which we started last week.
The exercises I have in mind are the following. We'll see how far we get, and continue on Monday.
... this is as far as we got during class. I've attached our code for 3.1 and 3.1 . We'll pick this up on Monday, and continue into chapter 3.2.
;; The lambda syntax we've seen already
(define f (lambda (x) (* 2 x))
(display (f 3))
;; And now this variation
(define g (lambda items (apply + items)))
(display (g 1 2 3))
... explain what's going on and how this is using "state".
;; from https://stackoverflow.com/questions/14674165/scheme-generate-random
(define random
(let ((a 69069) (c 1) (m (expt 2 32)) (seed 19380110))
(lambda new-seed
(if (pair? new-seed)
(set! seed (car new-seed))
(set! seed (modulo (+ (* seed a) c) m)))
(/ seed m))))
(display (random)) (newline)
(display (random)) (newline)
(display (random)) (newline)
(display (random 19590319)) ;;; what does this do that is different ?
See wikipedia: pseudorandom number generator for a discussion of the ideas behind these random generators.