A simple variable:
x = 10;
A simple function:
f[x] = x+2
------------------------------------------------------------------------------
There is nothing that says that a variable can't be function. When doing math
in class this likely isn't a thought that occurs often. It is common to have:
a[x] = b[x] = x+1
Where a[x] and b[x] are the same function. Intuitively, this is simple because
when we equate two functions we are dealing with two entities of the same
type. In math, we are used to doing:
a[x] = x+2
b = a[1]
And 'b' will have a value of 3. The "leap" to be made is allow yourself to do
the following:
a[x] = x+2
b = a;
four = b[2]
Here, we see that we treat the function 'a[x]' by its name only and we don't
give it anything to act on (essentially treating it the same way as a
variable). We say b = a, and this means that the variable 'b' is equal to the
function 'a'. If the variable 'b' is the same as the function 'a', then using
the variable 'b' *as if* it was a function (as in the example) makes sense.
------------------------------------------------------------------------------
Let's use longer, more descriptive names:
add_two[x] = x+2
This function will add two to x and that will be the result of the function
(what it returns implicitly)
------------------------------------------------------------------------------
Here's a simple notation for a function with no name. Notice that it is the
same as above, except that there is no name before the []:
[x] = x+2
On its own, the above unnamed function cannot do anything, so let's set it
to a variable:
add_two = ([x]=x+2)
This variable is now equal to the anonymous function, allowing us to access
the function through the name of the variable.
add_two[2] results in 4
It is now apparent that the following are equivalent:
add_two = ([x]=x+2)
add_two[x] = x+2
------------------------------------------------------------------------------
That was cool, so now let's make a more generalized solution for the problem
of adding two numbers:
adder[x] = ([y]=x+y)
add_two = adder[2];
add_two[2] results in 4.
also consider calling the adder function in this way:
four = adder[2][2]