Functions and recursion

Functions

Intro

Also called subroutines

Functions

We can call a function: \(y=f(x)\)

Here \(x\) are the local variables to be used.

However the global state may also affect the outcome, so we have:

\(y=f(x,z)\)

As a result, calling the same function twice with the same inputs can have different outputs.

Side effects. If a function modifies the state outside of its local variables it has side effects.

Recursion

Stack overflows

Write too many instructions to stack. can be caused by infinite recursion. eg fun x() return x()).

Other

Global and local variables