Documentation - nav343/Boron.bor GitHub Wiki

📃 Docs

A step-by-step guide to mastering Boron programming language. We will look at all (literally) the features, functions and properties of Boron Programming language.

Index

Page Short-Note
Basic and Installation Introduction and installing the Boron programming language.
Types Basic built in types.
Variables Variable declaration.
Functions Functions (declaration, usage)
Native Functions Native functions available in boronlang (literally all of 'em).

Basics

Boron is a cross-platform, easy to learn, fast and light weight programming language made for fun. Boron interpreter is available for Windows, MacOS and Linux.

Boron is dynamically typed and assigns the variable type at runtime depending on the value provided.

  • Installation

  • Prerequisites

Requires NodeJS, pkg, yarn, typescript compiler (tsc) for building.

[filename] -> replace a .bor file (use ./test/main.bor for testing) or leave it empty for entering repl more

  • Windows [Not Tested]

git clone https://github.com/nav343/Boron.bor.git
cd ./Boron.bor
yarn        # to install all the packages to ./node_modules
tsc         # compile ts to js
yarn build

# This will create a dist/build folder.
./dist/build/boron-win.exe [filename or '']
  • Linux

git clone https://github.com/nav343/Boron.bor.git
cd ./Boron.bor
yarn        # to install all the packages to ./node_modules
tsc         # compile ts to js
yarn build

./dist/build/boron-linux [filename or '']
  • Mac OS [Not Tested]

git clone https://github.com/nav343/Boron.bor.git
cd ./Boron.bor
yarn        # to install all the packages to ./node_modules
tsc         # compile ts to js
yarn build

./dist/build/boron-macos [filename or '']

Types

Boron has 5 types which are string, boolean, number, null and object

As mentioned above, boron is a dynamically typed programming language, so you don't need to specify any of the above types, boron automatically assigns the type at runtime.

You can check the variable's type by using the typeof() native function

Variables

In programming, a variable is a value that can change, depending on conditions or on information passed to the program. In boron, variables can be assigned using either the let keyword or the const keyword.

Variables assigned with the let are mutable meaning that their value can be changed and variables assigned with the const keyword are immutable meaning that their value cannot be changed, no variable can be re-assigned but their values can be changed (only if it is mutable).

Variable value can be of type int, float, string or object.

int stands for Integers and can store integer values, like 10, 12332, etc (note that -ve numbers are not supported at the moment)

float stands for floating point numbers and can store decimal (.) values, like 123.2, 123.12312, etc

string as the name suggests, stores string values (enclosed in "), like "hi there". At the moment boron only supports "___". String can be multi line or single line.

object stores key value pairs, like { name: "nav343" }, here "name" is the key and "nav343" is the value, the value can be of any type. Short hand values are valid, for example:

const name = "nav343";
const info = {
  name,
  age: 1
};

Later you can access name by info::name and age by info::age

Example:

$ this value can be modified
let intVar = 1234;

$ this cannot be modified
const floatVar = 234.3243;

let name = "nav343";
name = "nice name nav343"
let shortHandName = "nice name";

const info = {
  name: "nicename",
  age: 123456,
  shortHandName
};
print(info::name, info::age, info::shortHandName)

Functions

A function is simply a “chunk” of code that you can use over and over again, rather than writing it out multiple times. In boron you can use the func keyword, followed by an identifier and then by the body, to declare a function. For example -

func welcomeNewUser(name, otherInfo) {
  print(name)
  print(otherInfo)
}
const otherInfo = {
  age: 123,
  hobby: "making languages"
};

welcomeNewUser("nav343", otherInfo::age)
welcomeNewUser("nav343", otherInfo::hobby)

Here welcomeNewUser is a function which takes in 2 arguments - name and otherInfo, notice how you don't need to specify a type of these arguments.

Now you can use these 2 variables anywhere inside that function scope (inside those {...} basically).

For calling the function, you just have to type the name, followed by parentheses and arguments inside them (if any). Arguments are separated by commas ,

Native Functions

Some functions in boron programming language are reserved and are provided out of the box and can be used anywhere inside your project without needing to import any other file(s). Here is the list of all (that are available in the latest version) the built-in functions/ native functions -

Name Description Parameters Required Params
print Prints the given value to the console Pass in as many params you want None
typeof Returns the type of the value provided value -> anything Required
input Takes input from the user message -> string Required
getPass Same as input but doesn't echo what the user is typing, can be used for passwords message -> string Required
writeFile Writes the given data to a file in the directory fileName -> Name of the file, contents -> The data you want to write to fileName Required
readFile Reads the contents of a file fileName -> Name of the file you want to read Required
TIME Returns a formatted string containing current hour, minute and second - HH:MM:SS None None
clearScr Clears down the terminal session None None
exit Kills the current process with the code provided code -> 0 or 1 None (defaults to 0)
⚠️ **GitHub.com Fallback** ⚠️