# Enso

### Enso Project Structure

A typical Enso project structure might look like this:

```
my_enso_project/
├── src/
│   ├── Main.enso
│   └── MyModule.enso
├── packages/
│   └── Standard/
├── themes/
│   └── default.yaml
└── project.yaml
```

### Basic Enso Code

Here's a simple Enso code example (Main.enso):

```enso
from Standard.Base import all

main =
    print "Hello, Enso!"
    x = 10
    y = 20
    sum = x + y
    print "The sum is {sum}"
```

### Node.js Integration

Enso can interact with Node.js modules. Here's an example of how you might use a Node.js module in Enso:

```enso
from Standard.Base import all
import Standard.Node.Fs as Fs

main =
    content = "Hello, File!"
    Fs.writeFileSync "example.txt" content
    read_content = Fs.readFileSync "example.txt" "utf8"
    print read_content
```

### Custom Node.js Module for Enso

You can create custom Node.js modules to use in Enso. Here's an example:

1. Create a file named `customModule.js`:

```javascript
// customModule.js
module.exports = {
  greet: function(name) {
    return `Hello, ${name}!`;
  },
  add: function(a, b) {
    return a + b;
  }
};
```

2. Use the custom module in Enso:

```enso
from Standard.Base import all
import Standard.Node.Module as Module

main =
    custom_module = Module.require "./customModule.js"
    greeting = custom_module.greet "Enso"
    print greeting
    
    result = custom_module.add 5 7
    print "5 + 7 = {result}"
```

### Enso Runtime in TypeScript

Enso's runtime is written in TypeScript. Here's a simplified example of how you might define a custom datatype in the Enso runtime:

```typescript
// CustomType.ts
import { Atom, AtomConstructor } from "@enso-org/data-structures";

export class CustomType extends Atom {
  constructor(public value: string) {
    super();
  }

  static create(value: string): CustomType {
    return new CustomType(value);
  }

  toString(): string {
    return `CustomType(${this.value})`;
  }
}

export const CustomTypeConstructor: AtomConstructor<CustomType> = {
  create: CustomType.create,
};
```

### Enso Language Server

Enso uses a language server for IDE integration. Here's a basic example of how you might start the Enso language server using Node.js:

```javascript
// start-language-server.js
const { spawn } = require('child_process');
const path = require('path');

const serverPath = path.join(__dirname, 'enso-language-server.jar');
const server = spawn('java', ['-jar', serverPath]);

server.stdout.on('data', (data) => {
  console.log(`Server output: ${data}`);
});

server.stderr.on('data', (data) => {
  console.error(`Server error: ${data}`);
});

server.on('close', (code) => {
  console.log(`Server exited with code ${code}`);
});
```


---

# 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://fangdarth.gitbook.io/fangdarth/guides/enso.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.
