Order of Recursive Calls When ever a function call is made, it must return before we can do something. What ever is after the recursive call is executed after the recursion ends ...
CS61A: Tree Recursion
CS61A: Lecture 9
Tree Recursion Recursion Review How to Know That a Recursive Implementation is Correct: Tracing: Diagram the whole computational process (only feasilbe for small examples/cases) ...
CS61A: Lecture 8
Recursion Self-reference: A function refers to itself with its own name. Mutual Recursion: Mutual recursive functions call one another def add_next(n): print(n) return lambda f: subt...
CS61A: Recursion
Self-Reference In environments, functions may refer to their own name within the body (how environments are designed to be) def print_all(x): print(x) return print_all # Doesn't call i...
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...