Basic ideas for beginners
A function is like a machine.
Example:
Input: 2 → Output: 3
At first, functions were used only with numbers.
Example:
A function takes 5 and returns 6.
So functions were seen as number machines.
Later, people realised something important.
A function can take:
And the result does not have to be a number.
An object is just a thing.
Examples of objects:
This kind of function works directly on objects.
Some functions do not take things.
They take other functions as input.
This function does not care about numbers or objects. It only cares about another function.
Functions expect the right kind of input.
Mixing the wrong things causes errors.
To avoid confusion, functions are grouped by levels.
This keeps everything clear and safe.
A computer program is a special kind of function.
Some programs take data. Some programs take other programs. Some programs return new programs.