gluon

(Previously called embed_lang)

Build Status

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

Installation

Rust

Gluon is available at crates.io and can easily be included in a Cargo project by adding the lines below.

toml [dependencies] gluon = "0.1.0"

Other langauges

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.

REPL

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

REPL features: * Evaluating expressions (expressions of type IO will be evaluated in the IO context). * 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.
Example:

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

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 arguemnt 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

If you are interested in contributing to this project there are a few issues open marked as beginner which should be possible to for someone unfamiliar with the code. If you find something that looks interesting leave a comment on the issue so I know about it annd can give some assistance if needed.

Goals

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

Inspiration

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