Tip:
Highlight text to annotate it
X
So now we have the phenomenal cosmic power to define functions.
Once we have them, we can call them with actual arguments,
and then inside the function body we can return with the return value.
Function bodies are statements which can contain expressions.
So we'll be evaluating or interpreting quite a bit.
And this is a lot of power.
In fact, it's going to turn out that this is really all you need, pretty much,
to be just as powerful as any other programming language.
Recursive functions pack a wallop. There's a lot going on.
And that means that this is actually a double-edged sword.
With great power comes ... let's say lots of care that we have to take.
We've been writing together in Python a program that simulates,
interprets, evaluates JavaScript,
and this means that anything that JavaScript could do
we could also do in Python,
because if for some reason we didn't really know how to write it in Python,
we would just leave it in JavaScript and run our written in Python JavaScript interpreter.
It's a bit like that MC Escher drawing where 1 hand is drawing another hand
that's actually drawing the first in a bit of a recursive loop.
We can use language A to simulate or interpret language B.
So on the 1 hand, if you'll permit me,
I can write a Python program that simulates any JavaScript program.
That means that Python is at least as powerful as JavaScript.
We'll abbreviate JavaScript with JS.
It also turns out--not shown here, but it's actually very similar--
that I could write in JavaScript an interpreter for Python.
So JavaScript is at least as powerful as Python.
Both of these claims ignore speed because our interpreter or our web browser
might be a little slower than just running the appropriate code natively,
just as translating natural language text from Spanish into Mandarin Chinese
takes some amount of time.
But there's a strong sense in which these languages are equally expressive.
Any computation I could carry out in Python I could also carry out in JavaScript.
Any computation I could carry out in JavaScript I could also carry out in Python.
I can be just as creative in either language.
Now, one language may look prettier than another,
one language may take a little less time to say a certain thought,
to have a creative idea, but ultimately, I can express the same range of work,
emotions, desires in Python and in JavaScript.
This is pretty powerful stuff.