# History variables

Implemented as a class:

```ruby
class HistoryVar(v) {
 
    has history = []
    has variable = v
 
    method ≔(value) {
        history << variable
        variable = value
    }
 
    method to_s {
        "#{variable}"
    }
 
    method AUTOLOAD(_, name, *args) {
        variable.(name)(args...)
    }
}
 
var foo = HistoryVar(0)
 
foo ≔ 1
foo ≔ 2
foo ≔ foo+3
foo ≔ 42
 
say "History: #{foo.history}"
say "Current value: #{foo}"
```

#### Output:

```
History: [0, 1, 2, 5]
Current value: 42
```


---

# Agent Instructions: 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:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/h/history_variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
