Lecture 19
Imperative Programming - pt2
#lang htdp/asl
All the code for the rest of the quarter will be in the Advanced Student Language with the exception of Ex.6
Types and Type Signatures in imperative programs
-> number�-> string
number -> void�string -> void
The simplest possible imperative
; void : -> void�
(void)
Assignment statements
(set! name new-value)
The next simplest imperative is assignment (set!) often read "set bang"
Composing imperatives
Sequencing with begin
(begin expression-1 expression-2 …)
Looping as a sequencing primitive
(for-each func a-list)
Conditionals for Imperative Programming
(if test
imperative
other-imperative)
(when test
imperative)
(unless test
imperative)
Rules of computation in ASL
Look at the expression
Special forms: New Imperative Additions
If it starts with λ or lambda:
(λ (name1 … namelast) result-expression)
If it starts with the the word local
(local [(define name1 value1) � …� (define namelast valuelast)]� result-expression)
Imperative special forms
If it starts with set!
(set! name value-expression)
If it starts with the the word begin
(begin expressions …)
If it starts with when or unless:
(when test expression)