> For the complete documentation index, see [llms.txt](https://docs.cheddar.vihan.org/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cheddar.vihan.org/docs/developing/primitive-objects/scope.md).

# Scope

A scope is the most basic interpretation class. You can think of it as a glorified hashmap which can inherit. It's structure is:

```
             Scope
               |
  +------------+------------+
  |            |            |
scope     inheritance   interface
             chain          |
                        +---+---+
                        |   |   |
                       get set has
```

What is each part?:

* `scope`: a hashmap. The **key** is the variable name, the **value** is the value of the variable (this is usually a `CheddarVariable`, described later).
* `inheritance chain`: this is either **another Scope** class, or **`null`**. If this exists, its `scope` will also be navigated, acting as inheritance. This is so the class being inherited from is modified itself, rather than a copy of it.
* `interface`: this provides a **very raw interface** for `get`ting a variable, `set`ting a variable, or checking if it `has` a variable. These can be overwritten, but these methods are **not to be confused with** getters and setters.

All together this class can implement scopes. Here's an (psuedo-code) example of what is called when (the path the program takes is highlighted with `+`):

```javascript
a = 1;     + interface/set(a, 1)
           - if inheritance chain/has(a)
           -    inheritance chain/set(a, 1)
           + else
           +    scope/set(a, 1)

{
    a = 1  + interface/set(a, 1)
           + if inheritance chain/has(a)
           +    inheritance chain/set(a, 1)
           - else
           -    scope/set(a, 1)
}

print a;   + interface/get(a)
           - if inheritance chain/has(a)
           -    inheritance chain/get(a)
           + else
           +    scope/get(a, 1)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cheddar.vihan.org/docs/developing/primitive-objects/scope.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
