Tuesday - Lecture 14 - Intro to Imperatives
Date: July 14
Date: July 14
Today marks a momentous occasion! We leave behind “purely” functional programming for the auspices of imperative programming. While this gives us the power to change the state of our computer (and used that changed state as parts of our programs), it also comes with increased responsibility to monitor side-effects of our programs.
Some good checks of understanding for today’s lecture!
; Why is this an exception by itself?
(set! x 5)
; Why is this okay now?
(lambda ()
"hello")
; Why is this an exception?
(define x 1)
(lambda ()
(set! x (+ x 1))
(set! x (+ x 1))
(set! x (+ x 1)))
; What type of data does this return?
(define x 1)
(define (cool-func)
(begin (set! x (+ x 1))
(set! x (+ x 1))
(set! x (+ x 1))))
(cool-func)
; What about this?
(define x 1)
(define (cool-func-1)
(begin (set! x (+ x 1))
(set! x (+ x 1))
(set! x (+ x 1)))
x)
(cool-func-1)
In-Class Resources
| Link | Title | Type | Duration |
|---|---|---|---|
| Video 1 | Lecture 14.1 - Intro | pre-recorded | 10:33 |
| Video 2 | Lecture 14.2 - Primitive Imperatives | pre-recorded | 7:30 |
| Video 3 | Lecture 14.3 - Composing Imperatives | pre-recorded | 6:20 |
| Video 4 | Lecture 14.4 - Looping Imperatives | pre-recorded | 4:03 |
| Video 5 | Lecture 14.5 - Imperative Bugs | pre-recorded | 1:58 |
| Video 6 | Lecture 14.6 - Higher Order Imperatives | pre-recorded | 5:12 |
Mini-Quiz 14: Imperative Basics
To take the mini-quiz associated with this lecture's content, you can use this link or find the quiz under the Quizzes page on Canvas.