Home
Alexander Lu
Cancel

CS61A: Lecture 6

Decorators We can wrap functions with another function such that whenever we call the function itself, it is being used as an argument for the decorator function. def trace(fn): """Return ...

CS61A: Lecture 7

Lecture Function Examples def nearest_prime(n): k = 0 while True: if (is_prime(n+k)): return n+k if is_prime(n-k): k = -k else: k+=1 curry = lambda f: lambda x: lambda y: f(...

CS61A: Decorators

Decorators We can wrap functions with another function such that whenever we call the function itself, it is being used as an argument for the decorator function. def trace(fn): """Return ...

CS61A: Lecture 6

Lecture Zero-Argument Functions Yes, functions can take 0 arguments. Functions always re-evaluate their bodies when called. Dice Functions In the Hog project, dice are functions that are...

CS61A: Functional Abstraction

Lambda Function Environments A lambda function’s parent is the frame where the lambda expression is evaluated (where lambda appears). a = 1 def f(g): a = 2 return lambda y: a * g(y) # ...

CS61A: Lecture 5

Lecture

CS61A: Function Currying

Function Currying We manipulate functions such that instead of posessing multiple arguments, they become a higher order function that accepts a single argument and returns other functions to pro...

CS61A: Lambda Expressions

Lambda Expressions Expressions that evaluate to a function. We can directly assign a name to a function without defining it in our frame with def x = 10 square = x * x ...

CS61A: Environments for Higher-Order Functions

Higher Order Functions are enabled by Environments Higher-order Function: A function that takes a function as an argument or returns a function as a return value. def apply_twice(f, x): return...

CS61A: Lecture 4

Designing Functions 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 possibly return ...