bblang

a simple language for processing information

Introduction

BBLANG is a simple programming language for processing information. It supports JSON natively and is built from the ground up to make working with them intuitive. It has a simple yet expressive syntax that feels familiar to C/Java/JavaScript family of users.

Code Organization

BBLANG is a procedural programming language, and hence a typical solution in BBLANG is expressed in the form of functions that make use of other functions to solve a problem. On a top level, programs are organized as modules that defines functions within them. There is the familiar concept of private and public functions, where private functions are available for use only within the module and public functions are exported for use in other modules. Public functions have a name with a colon (":") in them. So "user:auth", "user:create", "user:delete" are examples of names of public functions while "createUser", "deleteUser" are examples of private functions.

Types, Variables & Context

BBLANG natively supports JSON and hence the type system is composed of number, string, list, map and function. Boolean has a special treatment in BBLANG, in that they are called "Betals" that stand for "Boolean et. al." as they also accommodate "null" under the Betal type. Functions are first class citizens and can be treated like normal values, so that you may freely assign them to variables and pass it around as arguments to other functions. In BBLANG there is no need to declare variables, you can directly start assigning them values. The scope of a variable is the function in which it is defined, and hence cannot be modified outside of the function in which it is defined. Also, there is no global scope, every variable must be housed inside a function. A function defined inside a function captures the variables of the parent function, in a read-only fashion and hence not modifiable.

Functions

Functions in BBLANG look a lot like JavaScript functions and yes arrow syntax and default arguments are supported. The return value of a function is the value of the last expression evaluated, although you can manually return at any point using the regular return syntax. The arrow syntax is used when the definition consists of only a single statement. The special variable "args" contains the arguments supplied to the function as a list, and "self" refers to current function providing a way for writing anonymous recursive functions.

Dot notation

The "dot" in BBLANG serves two purposes, it can be (like in JavaScript) used to access the value of a key in a map and also lets you call standard library functions in an intuitive way. It is therefore perfectly OK to use a dot after a number, string, list or function in which case the corresponding standard library function is called with the parent supplied as the first argument. If the standard library function requires only one argument the parentheses (or call operator '()') is optional. In the case of map, a library function is invoked only if the map does not already contain an entry for the supplied key.

Conditional Statements

BBLANG supports both "if" and "switch" conditional statements. The parentheses surrounding the condition is optional, but is required when multiple expressions are to be evaluated. The syntax for the switch statement deviates from the normal syntax where every case condition is enclosed within curly braces and are optional if there is only statement to be executed. There is no colon (":") after a case expression.

Loops

The supported loop statements in BBLANG are "for", "while" and "do while". The syntax is very much similar to their JavaScript counterparts but again the parentheses are optional. BBLANG also supports the "for in" variant which can be used to iterate over the elements in a list or keys in a map.

hello(msg) => { return "hello " + msg }, exclaim(msg) => { return msg + "!" }, "foo,bar,baz".split(",").map(hello).map(exclaim)