GithubHelp home page GithubHelp logo

silky / bosatsu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnynek/bosatsu

0.0 2.0 0.0 784 KB

A python-ish pure and total functional programming language

License: Apache License 2.0

Python 2.45% Java 0.06% Scala 97.43% Vim Script 0.06%

bosatsu's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.