Variables and Functions
beginnerIn the previous problem, you worked with numbers directly in expressions.
But programming is not just about computing with values — it’s about naming them. That’s how we reuse, generalize, and communicate clearly in code.
Instead of writing 3.14159 everywhere, you can give it a name like "pi". Then you can use "pi" in your expressions — and change its value in just one place.
What You’ll Do
In this problem, you’ll define names for values using expressions like:
["pi", "=", 3.14159];
And use names by just referring to them:
"pi";
Then you’ll go further and define functions — named rules that describe how to compute something from an input.
Behind the scenes, an evaluator keeps track of which name maps to which value. You don’t need to write the full evaluator — just a few simple rules that explain how to define and use names, and how to call functions.
Let’s get started.