> For the complete documentation index, see [llms.txt](https://docs.budgielang.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.budgielang.org/syntax/standalone-functions/main.md).

# Main

All languages provide some way to execute code immediately.

Scripting languages such as Python and Ruby will execute all code in order immediately, whereas class-based languages such as C# and Java require a class wrapping a static method akin to C/C++'s "main" function.

Budgie resolves the differences by declaring an area as a "main context" with `main context start` and `main context end`. A main function may be declared within that context with `main start` and `main end`.

```
main context start
    main start
        print : ("Hello world!")
    main end
main context end
```

In C#:

```csharp
using System;

class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello world!");
    }
}
```

In Python:

```python
if __name__ == "__main__":
    print("Hello world!")
```

## Functions

Main contexts, other than the way they're declared, are functionally identically to standalone function groups. That means you can still declare standalone functions within them.

```
main context start
    standalone function declare start : private SayHello void name string
        print : { concatenate : ("Hello, ") name "!" }
    standalone function declare end

    main start
        standalone function : private { main group } SayHello "Budgie"
    main end
main context end
```

In C#:

```csharp
using System;

class Program
{
    private void SayHello(string name)
    {
        Console.WriteLine("Hello, " + name + "!");
    }

    public static void Main()
    {
        SayHello("Budgie");
    }
}
```

In Python:

```python
def say_hello(name):
    print("Hello, " + name + "!")

if __name__ == "__main__":
    say_hello("Budgie")
```

> Function names must be given in PascalCase so that Budgie can transform them into the appropriate case for the output language. JavaScript, for example, prefers camelCase, while Python prefers snake\_case.


---

# 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.budgielang.org/syntax/standalone-functions/main.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.
