Transcript from the "Variable Evaluation" Lesson
>> Steve Kinney: We added define. We do need to go and make sure that we can evaluate it however. So let's get that in place.
>> Steve Kinney: Cool, we'll go into evaluate.
>> Steve Kinney: Now we have this new type of node. So let's go ahead and make the helper function first. We'll say,
>> Steve Kinney: I think define is a great name for it. But if you named yours something else, then define might not be the best name for you. It's just the best name for me. define, I will say node and all we have to do is add it to the environment.
>> Steve Kinney: And it'll be node.identifier,
>> Steve Kinney: .name = node.assignment.value.
>> Steve Kinney: And then we'll say
>> Steve Kinney: If the node.type now equals this new kinda syntax and yeah, could you come up with, is this gonna grow over time? Sure, right, could you come up with some other abstractions? Absolutely.
>> Steve Kinney: Declaration return.
>> Steve Kinney: define(node). All right, I think I'm gonna take it for a spin in my REPL cuz I'm worth it.
>> Steve Kinney: Let's see if made any mistakes.
>> Steve Kinney: (define x 10), whoop, cannot read property type of undefined. All right, I'm gonna take a second and take a look at that, and I'll get right back to you.
[00:01:58] So I'm gonna take out that console.log unless it breaks again.
[00:02:27] Right, I now have variable declarations. That was adding a, guess, probably an important language feature. Not that bad, right? And again, we chose a simple language with a very kind of easy syntax for that. But I still think it is super interesting to be able to have that in place.
[00:02:48] All right sweet.
>> Speaker 2: So what was the fix?
>> Steve Kinney: What's up?
>> Speaker 2: Where did you?
>> Steve Kinney: The fix was when I wrote that transformation, right, originally this was a function that took the node and then returned it back out. Here, this is supposed to pass everything along through the pipeline.
[00:03:08] And because I didn't return node, it returned undefined to evaluate. Evaluate tried to find type on undefined. Everything went poorly.