<commit_before># gluon

[![Build Status](https://travis-ci.org/gluon-lang/gluon.svg?branch=master)](https://travis-ci.org/gluon-lang/gluon) [![Gitter](https://badges.gitter.im/gluon-lang/gluon.svg)](https://gitter.im/gluon-lang/gluon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Documentation](https://docs.rs/gluon/badge.svg)](https://docs.rs/crate/gluon)

Gluon is a small, statically-typed, functional programming language designed for application embedding.

## Features

* **Statically typed** - Static typing makes it easier to write safe and efficient interfaces between gluon and the host application.

* **Type inference** - Type inference ensures that types rarely have to be written explicitly giving all the benefits of static types with none of the typing.

* **Simple embedding** - Marshalling values to and from gluon requires next to no boilerplate, allowing functions defined in [Rust][] to be [directly passed to gluon][easy_embed].

* **UTF-8 by default** - Gluon supports unicode out of the box with utf-8 encoded strings and unicode codepoints as characters.

* **Separate heaps** - Gluon is a garbage-collected language but uses a separate heap for each executing gluon thread. This keeps each heap small, reducing the overhead of the garbage collector.

* **Thread safe** - Gluon is written in Rust, which guarantees thread safety. Gluon keeps the same guarantees, allowing multiple gluon programs to run in parallel ([example][parallel])\*

[easy_embed]:https://github.com/gluon-lang/gluon/blob/master/TUTORIAL.md#embedding-api
[parallel]:https://github.com/gluon-lang/gluon/blob/master/tests/parallel.rs

\* Parallel execution of gluon programs is a recent addition and may still have issues such as deadlocks.

## Usage

### Try online

You can try gluon in your browser at the [try_gluon](http://172.16.31.10:8080/) server. ([Github](https://github.com/gluon-lang/try_gluon))

### Installation

#### Rust

Gluon requires a recent Rust compiler to build (1.9.0 or later) and is available at [crates.io](https://crates.io/crates/gluon). It can easily be included in a Cargo project by adding the lines below.

```toml
[dependencies]
gluon = "0.6.2"
```

#### Other languages
Currently the easiest way to interact with the gluon virtual machine is through Rust but a rudimentary [C api][] exists which will be extended in the future to bring it closer to the Rust api.

[C api]: https://github.com/gluon-lang/gluon/blob/master/c-api/src/lib.rs

## Tools

### Visual Studio Code Extension

The [gluon extension][] for Visual Studio Code provides syntax highlighting and completion. To install it, search for `gluon` among the extensions. ([Github](https://github.com/gluon-lang/gluon_language-server)) 

![example](http://i.imgur.com/44bH0ww.gif)

[gluon extension]:https://marketplace.visualstudio.com/items?itemName=Marwes.gluon

### REPL

Gluon has a small executable which can be used to run gluon programs directly or in a small REPL. The REPL can be started by passing the `-i` flag to the built repl executable which can be run with `cargo run -- -i`.

REPL features:
* Evaluating expressions (expressions of type IO will be evaluated in the IO context).
* Bind variables by writing `let <pattern> <identifier>* = <expr>` (omitting `in <expr>` from a normal let binding)
    Example:

         let f x = x + 1
         let { x, y = z } = { x = 1, y = 2 }
         f z

* Printing help about available commands with `:h`
* Loading files with `:l path_to_file` the result of evaluating the expression in the loaded file is stored in a variable named after the filename without an extension.
* Checking the types of expressions with `:t expression`
*   Printing information about a name with `:i name`.<br>
    Example:

        :i std.prelude.List
        type std.prelude.List a = | Nil | Cons a (std.prelude.List a)
        /// A linked list type

* Tab-completion of identifiers and record fields
    ![repl completion](http://i.imgur.com/IXLQFtV.gif)
* Exit the REPL by writing `:q`

### Vim plugin

[vim-gluon](https://github.com/salpalvv/vim-gluon) is a vim plugin which provides basic syntax highlighting and indentation.

## Documentation

[Tutorial (WIP)](https://github.com/gluon-lang/gluon/blob/master/TUTORIAL.md)

[Rustdoc](https://docs.rs/gluon/*/gluon/index.html)

## Examples

## Hello world

```f#,rust
let io = import! "std/io.glu"
io.print "Hello world!"
```

## Factorial

```f#,rust
let factorial n : Int -> Int =
    if n < 2
    then 1
    else n * factorial (n - 1)

factorial 10
```

### Syntax<commit_msg>Expand the vim support in the readme<commit_after># gluon

[![Build Status](https://travis-ci.org/gluon-lang/gluon.svg?branch=master)](https://travis-ci.org/gluon-lang/gluon) [![Gitter](https://badges.gitter.im/gluon-lang/gluon.svg)](https://gitter.im/gluon-lang/gluon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Documentation](https://docs.rs/gluon/badge.svg)](https://docs.rs/crate/gluon)

Gluon is a small, statically-typed, functional programming language designed for application embedding.

## Features

* **Statically typed** - Static typing makes it easier to write safe and efficient interfaces between gluon and the host application.

* **Type inference** - Type inference ensures that types rarely have to be written explicitly giving all the benefits of static types with none of the typing.

* **Simple embedding** - Marshalling values to and from gluon requires next to no boilerplate, allowing functions defined in [Rust][] to be [directly passed to gluon][easy_embed].

* **UTF-8 by default** - Gluon supports unicode out of the box with utf-8 encoded strings and unicode codepoints as characters.

* **Separate heaps** - Gluon is a garbage-collected language but uses a separate heap for each executing gluon thread. This keeps each heap small, reducing the overhead of the garbage collector.

* **Thread safe** - Gluon is written in Rust, which guarantees thread safety. Gluon keeps the same guarantees, allowing multiple gluon programs to run in parallel ([example][parallel])\*

[easy_embed]:https://github.com/gluon-lang/gluon/blob/master/TUTORIAL.md#embedding-api
[parallel]:https://github.com/gluon-lang/gluon/blob/master/tests/parallel.rs

\* Parallel execution of gluon programs is a recent addition and may still have issues such as deadlocks.

## Usage

### Try online

You can try gluon in your browser at the [try_gluon](http://172.16.31.10:8080/) server. ([Github](https://github.com/gluon-lang/try_gluon))

### Installation

#### Rust

Gluon requires a recent Rust compiler to build (1.9.0 or later) and is available at [crates.io](https://crates.io/crates/gluon). It can easily be included in a Cargo project by adding the lines below.

```toml
[dependencies]
gluon = "0.6.2"
```

#### Other languages
Currently the easiest way to interact with the gluon virtual machine is through Rust but a rudimentary [C api][] exists which will be extended in the future to bring it closer to the Rust api.

[C api]: https://github.com/gluon-lang/gluon/blob/master/c-api/src/lib.rs

## Tools

### REPL

Gluon has a small executable which can be used to run gluon programs directly or in a small REPL. The REPL can be started by passing the `-i` flag to the built repl executable which can be run with `cargo run -- -i`.

REPL features:
* Evaluating expressions (expressions of type IO will be evaluated in the IO context).
* Bind variables by writing `let <pattern> <identifier>* = <expr>` (omitting `in <expr>` from a normal let binding)
    Example:

         let f x = x + 1
         let { x, y = z } = { x = 1, y = 2 }
         f z

* Printing help about available commands with `:h`
* Loading files with `:l path_to_file` the result of evaluating the expression in the loaded file is stored in a variable named after the filename without an extension.
* Checking the types of expressions with `:t expression`
*   Printing information about a name with `:i name`.<br>
    Example:

        :i std.prelude.List
        type std.prelude.List a = | Nil | Cons a (std.prelude.List a)
        /// A linked list type

* Tab-completion of identifiers and record fields
    ![repl completion](http://i.imgur.com/IXLQFtV.gif)
* Exit the REPL by writing `:q`

### Language server

Gluon has a [language server](https://github.com/gluon-lang/gluon_language-server) which provides code completion and formatting support. Installation is done with `cargo install gluon_language-server`.

### Visual Studio Code Extension

The [gluon extension][] for Visual Studio Code provides syntax highlighting and completion. To install it, search for `gluon` among the extensions. ([Github](https://github.com/gluon-lang/gluon_language-server)) 

![example](http://i.imgur.com/44bH0ww.gif)

[gluon extension]:https://marketplace.visualstudio.com/items?itemName=Marwes.gluon

### Vim plugin

[vim-gluon](https://github.com/salpalvv/vim-gluon) provides syntax highlighting and indentation.

The gluon language server has been tested to work with https://github.com/autozimu/LanguageClient-neovim and https://github.com/prabirshrestha/vim-lsp. 

#### Example configuration (autozimu/LanguageClient-neovim)
```
let g:LanguageClient_serverCommands = {
    \ 'gluon': ['gluon_language-server'],
    \ }

" Automatically start language servers.
let g:LanguageClient_autoStart = 1

nnoremap <silent> K :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
```

## Documentation

[Tutorial (WIP)](https://github.com/gluon-lang/gluon/blob/master/TUTORIAL.md)

[Rustdoc](https://docs.rs/gluon/*/gluon/index.html)

## Examples

## Hello world

```f#,rust
let io = import! "std/io.glu"
io.print "Hello world!"
```

## Factorial

```f#,rust
let factorial n : Int -> Int =
    if n < 2
    then 1
    else n * factorial (n - 1)

factorial 10
```

### Syntax
{'fraction_non_alphanumeric': 0.11600646725949879, 'fraction_numerical': 0.006568310428455942, 'mean_word_length': 4.160062565172054, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 35, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6898042', 'n_tokens_mistral': 3258, 'n_tokens_neox': 3036, 'n_words': 1093}