> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/syntax_and_semantics/constants.md).

# Constants

Sidef implements three kinds of constants: `const`, `define` and `enum`.

## const

The common way of declaring constants in Sidef, is by using the `const` keyword:

```ruby
const pi = 3.14
say pi                 # prints: 3.14
#pi = 3                # compile-time error: can't modify non-lvalue constant
```

This kind of constants are created dynamically at run-time, but cannot be changed during the execution of the program.

When declared inside a class or a function, the constant is created and initialized dynamically, as illustrated in the following example:

```ruby
func f(a) {
    const x = a          # created dynamically at each function call
    return (x + 2)
}

say f(40)       #=> 42
say f(50)       #=> 52
```

## define

This keyword will define a compile-time evaluated constant and will point directly to the object at which it evaluated to.

```ruby
define PHI =   (1.25.sqrt + 0.5)
define IHP = (-(1.25.sqrt - 0.5))

say (PHI**7 - IHP**7 / PHI-IHP)
```

This type of constants are the most efficient ones.

## enum

The `enum` keyword will automatically declare and assign a list of constants with ascending numeric values (starting from 0):

```ruby
enum |Black, White|
say Black             # prints: 0
say White             # prints: 1
```

Alternatively, we have the possibility for specifying an initial value, which will get incremented after each declaration, by calling the method `.inc()`.

```ruby
enum |α="a", β|
say α             # prints: 'a'
say β             # prints: 'b'
```


---

# 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://trizen.gitbook.io/sidef-lang/syntax_and_semantics/constants.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.
