graeme-lockley / bendu-lang

A strongly typed strict functional language with multiple backends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bendu-lang

Bendu is a statically typed programming language that is designed to be simple, easy to use, fast and efficient.

I love tinkering around with programming languages trying to understand the techniques used to implement them. I have been working on a number of projects in little languages and rebo-lang exploring these techniques. In particular, Rebo was a very interesting project that I worked on as the following properties emerged:

  • The start up time was very fast - it felt instantaneous. This had the effect of being able to do things very quickly without any wait. Psychologically this was very satisfying.
  • The language is very simple and easy to use. It is a joy to write code in Rebo.
  • The testing cycle was very easy in that Rebo supported an executable markdown format that allowed tests to be written in a markdown file in a conversational style. Consider the language basics documentation for Rebo as an example. Further take a look at a parser and it's bytecode compiler as examples of how this works. It is worth noting that executing the markdown files to verify the assertions in these three examples takes 11ms, 52ms and 59ms respectively on a 2017 i7 iMac. This is very fast and makes the testing cycle very quick.

I have been thinking about how to combine these properties into a new language and Bendu is the result. The language is designed to be simple and easy to use, fast and efficient and to support a conversational style of testing.

Primary influences on Bendu are:

Bendu has the following features:

  • Statically typed with type inference
  • Local and remote packages
  • First class functions
  • Pattern matching
  • Algebraic data types
  • Script based

The tooling is written in Zig with ancillary tools written in Bendu.

A final comment. Bendu has multiple ways of executing code - it is AST based interpreted, bytecode compiled, WASM compiled and native compiled using LLVM. The AST interpreter is used for testing and the other methods are used for production. The AST interpreter is very fast and is used to execute the markdown tests.

Examples

The first 1,000 prime numbers:

let prime?(n) {
  let loop(i = 2) =
    if i * i > n -> True
     | n % i == 0 -> False
     | loop(i + 1)

  if n < 2 -> False
   | loop()
}

let primes(n) =
  range(2, n)
    |> filter(prime?)

println("The first 1000 prime numbers are: ", primes(1000))

See also

  • TODO is the implementation TODO list.
  • Scenarios is the functional description of Bendu and is the definitive guide for the language's behavior. It is also the automated test pack for the language and will exercise both the AST and BC implementation.
  • Where does the name "Bendu" come from? I am an annoyingly big fan of Star Wars and Bendu is a character in Star Wars Rebels. The character is a force sensitive being that is neither Jedi nor Sith; a neutral force that is neither good nor evil. I thought this was a good name for a language that is designed to be simple and easy to use, fast and efficient, supports a conversational style of testing and sits between functional, imperative and object styles as well as interpreted and compiled.
  • I have embedded Zigline into the interpreter to provide a REPL. Using Zigline is a temporary solution, but it works for now. Until Zig stabilizes its package management and build tools, we'll have to rely on it.

About

A strongly typed strict functional language with multiple backends

License:MIT License


Languages

Language:Zig 100.0%