Higher-order functions: can accept functions as arguments or return
functions as values
Higher-order functions are a more powerful means of abstraction than
user-defined functions, expressing general methods of computation,
regardless of the particular functions they call
By mapping each general concept or equation with its own short function, the
global becomes cluttered with unique function names, and we are constrained
by particular function signatures. Nested function definitions address
both.
Lexical scope: names are shared among nested definitions
Function parent: the first frame of the environment in which the
function was defined. When that function is called, the frame created has
the same parent
Extended environments: by calling nested functions, we can create longer
chain of frames
Lexical scoping can reduce global function names and help nested functions
share an environment
Locally defined functions maintain their parent environments when they are
returned
Currying: converting a function that takes multiple arguments into a
chain of functions that each take a single argument using higher-order
functions
Lambda expressions: evaluates to a function that has a single return
expression. Assignment and control statements are not allowed
Functions in Python are granted “first-class” status:
They may be bound to names
They may be passed as arguments to functions
They may be returned as results of functions
They may be included in data structures
Decorators: used for tracing, affects def statement and the function
attached by extending its behavior without explicitly changing it
Lecture 4: Higher-Order Functions (11/05/22)
Project 1: The Game of Hog (11-15/05/22)
*args syntax: used to pass an arbitrary amount of arguments into a function
Lecture 5: Environments (20/05/22)
Homework 02: (20-21, 24/05/22)
It is advantageous to consider input as both function and value