Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECS 111 Review 11/13/2016.

Similar presentations


Presentation on theme: "EECS 111 Review 11/13/2016."— Presentation transcript:

1 EECS 111 Review 11/13/2016

2 Imperative Programming
Prior to learning imperative programming, all expressions had some “value” Constants have their own value (i.e. 5 is 5) Variables have whatever value they were assigned Some special forms exist (define, local, lambda, if) If it’s none of the above, it’s a procedure call

3 That’s Nice and All… But imperatives are different
For example, set! is a void function Ex: (define x 5) (set! x 10) > x 10

4 Define vs. Set! Set! changes an existing variable’s value while the program is executing Define makes new variables

5 Functional vs Imperative
The only effect of a functional program is its return value Result does not depend on order Value determined entirely by inputs Imperative programs on the other hand… Many different effects Return value, variable changes, delete files, etc. Can influence other functions as well

6 Imperative Advantages
Usually more efficient (less steps to machine code) = faster code Can be simpler Simulations (these are basically just a bunch of changes, so it makes sense) More natural

7 Composing Imperatives
Sequencing Begin Conditionals If, when, unless, cond Repetition for-each recursion

8 begin Executes a bunch of expressions in order, and then returns the value of the last thing executed (begin (set! balance (+ balance amount)) balance) Would return balance after setting the balance to balance + amount

9 Imperative Special Forms
Set! Begin When/unless cond

10 Debugging! I’d look at Ian’s slides on this, but let’s walk through an example!

11 Exercise 6 Any other questions?
Any questions about the homework so far?


Download ppt "EECS 111 Review 11/13/2016."

Similar presentations


Ads by Google