Iteration

while Statements

Execution rule:

  1. Evaluate the header’s expression
  2. If it’s a true value, execute the (whole) suite, then return to step 1

Designing Functions

Three characteristics of functions that are really important:

  • A function’s domain is the set of all inputs it might possibly take as arguments.
  • A function’s range is the set of output values it might possible return.
  • A pure function’s behavior is the relationship it creates between input and output.

A Guide to Designing Functions

  • Give each function eactly one job, but make it apply to many related situations
  • Don’t repeat yourself. Implement a process just once.
>>> round(1, 23)
1
>>> round(1.23, 1) # round to 1 decimal place
1.2
>>> round(1.23, 0) # roudn to integer
1

Higher Order Functions

Generalizing over Computational Processes

A higher order function is a function that takes in another function as an argument.

Example, summation and make_adder

Locally Defined Functions

Functions defined within other function bodies are bound to names in a local frame.

An operator is any expression that evaluates to a function. So, in

make_adder(1)(2)

make_adder(1) is the operator.

Hey, kudos for making it this far! If you've liked this, you might also like tmux Cheatsheet and Shortcuts.