Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a note on scope lookup #1432

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions scope & closures/ch1.md
Expand Up @@ -236,10 +236,12 @@ To visualize the process of nested *Scope* resolution, I want you to think of th

<img src="fig1.png" width="250">

The building represents our program's nested *Scope* rule set. The first floor of the building represents your currently executing *Scope*, wherever you are. The top level of the building is the global *Scope*.
The building represents our program's nested *Scope* rule set. The first floor of the building represents your currently executing *Scope*, wherever you are. The top level of the building is the global *Scope*.

You resolve LHS and RHS references by looking on your current floor, and if you don't find it, taking the elevator to the next floor, looking there, then the next, and so on. Once you get to the top floor (the global *Scope*), you either find what you're looking for, or you don't. But you have to stop regardless.
You resolve LHS and RHS references by looking on your current floor, and if you don't find it, taking the elevator to the next floor, looking there, then the next, and so on. Note that LHS And RHS references and not checked in the other flats on the same level, just upwards. Once you get to the top floor (the global *Scope*), you either find what you're looking for, or you don't. But you have to stop regardless.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand what is being said here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your diagram you have several flats/apartments ( white boxes) at each floor. I just thought the reader will presume the reference lookup will check each apartment on the floor. But I think you are saying just the floor is checked. Or another way of showing that is to update the diagram to only have only one apartment ( white box) per floor in the building.


A better analogy is that of a Russian doll. Where several dolls are nested within each other. And you look for the reference in the current executing doll. If you dont find it you ask the outer doll and keeping asking each outer doll. You dont ask for the reference to its inner doll. If the biggest doll (the outer most doll is the global scope) does not have the refernce you are looking for then you stop.

## Errors

Why does it matter whether we call it LHS or RHS?
Expand Down