gluon

Build Status Gitter Documentation

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

Features

* 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 server. (Github)

Installation

Rust

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

toml [dependencies] gluon = "0.6.1"

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.

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)

example

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

Vim plugin

vim-gluon is a vim plugin which provides basic syntax highlighting and indentation.

Documentation

Tutorial (WIP)

Rustdoc

Examples

Hello world

f#,rust 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

Larger example which display most if not all of the syntactical elements in the language.

``f#,rust //let` declares new variables. let id x = x

let factorial n = if n < 2 then 1 else n * factorial (n - 1)

// type is used to declare a new type. // In this case we declare Countable to be a record with a single field (count) which is a function // taking a single argument and returning an integer type Countable a = { count : a -> Int }

// "Counting" an integer just means returning the integer itself let countable_Int : Countable Int = { count = \x -> x }

let listmodule = // Declare a new type which only exists in the current scope type List a = | Cons a (List a) | Nil let map f xs = match xs with | Cons y ys -> Cons (f y) (map f ys) | Nil -> Nil // Define a count instance over lists which counts each of the elements and sums // the results let countableList c : Countable a -> Countable (List a) = let count xs = match xs with | Cons y ys -> c.count y + count ys | Nil -> 0 { count } { // Since List is local we export it so its constructors can be used // outside the current scope List, countable_List, map }

// Bring the List type and its constructors into scope let { List, countableList } = listmodule

// Create a Countable record for List Int let { count } : Countable (List Int) = countableList countableInt

if count (Cons 20 (Cons 22 Nil)) == 41 then error "This branch is not executed" else io.print "Hello world!" ```

Contributing

There are many ways to contribute to gluon. The two simplest ways are opening issues or working on issues marked as beginner. For more extensive information about contributing, you can look at CONTRIBUTING.md.

Goals

These goals may change or be refined over time as I experiment with what is possible with the language.

Inspiration

This language takes its primary inspiration from Lua, Haskell and OCaml.