silky / bosatsu

A python-ish pure and total functional programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Bosatsu Programming Language

Bosatsu (菩薩) is the transliteration in Japanese of the sanskrit bodhisattva. A bodhisattva is someone who can reach enlightenment but decides not to, to help others achieve that goal. -- Wikipedia

Bosatsu is a simple, non-turing complete language designed for configuration, queries and scripting. It borrows from Python, Haskell, Dhall and Rust.

An example of Bosatsu

Here is a working Bosatsu program to solve the first Project Euler problem:

package Euler/One

# see:
# https://projecteuler.net/problem=1
# Find the sum of all the multiples of 3 or 5 below 1000.

def filter(as, fn):
  as.foldLeft([], \tail, item ->
    if fn(item): [item, *tail]
    else: tail)

under1000 = range(1000)

def or(a, b):
  True if a else b

def keep(i):
  or(i.mod_Int(3).eq_Int(0), i.mod_Int(5).eq_Int(0))

def sum(as):
  as.foldLeft(0, add)

# >>> sum(i for i in xrange(1000) if keep_fn(i))
# 233168
computed = trace("computed", under1000.filter(keep).sum)

test = Assertion(computed.eq_Int(233168), "expected 233168")

For more details see the language guide in particular the section on syntax

Use cases

Currently we have only implemented type-checking, the package system, and an interpreter to evalute expressions. This could already be useful if you want to give some programmability to configuration that can load, type-check and evaluate the configuration before executing the rest of the scala or java code.

As a JSON templating engine

Along with Bazel Bosatsu can be used as a JSON generation system, which could be useful for generating complex configurations in a way that has type-checking and ability to compose. For a working example see this example.

cd test_workspace
bazel build ...
cat bazel-build/testjson.json

Future features

We would like to implement a number of features:

  1. a REPL
  2. a java backend and bazel rules which can call java and scala functions
  3. a skylark backend to allow writing strongly typed bazel rules compiling to untyped skylark

About

A python-ish pure and total functional programming language

License:Apache License 2.0


Languages

Language:Scala 97.4%Language:Python 2.5%Language:Vim Script 0.1%Language:Java 0.1%