abacus/abacus-core
Joe Bellus 4efb5c1853
continuous-integration/drone/pr Build is passing Details
Math & Phyics Constants
Scripting now has a math and physics module which include several
basic constants
2022-10-19 23:47:51 -04:00
..
src Math & Phyics Constants 2022-10-19 23:47:51 -04:00
test Foundational UI (#1) 2022-10-16 18:14:55 +00:00
Cargo.toml Foundational UI (#1) 2022-10-16 18:14:55 +00:00
README.org CI/CD Pipelines (#2) 2022-10-17 02:59:09 +00:00

README.org

Abacus Core

Abacus core provides the scripting and calculation engine for Abacus.

For General information visit Abacus For information on the UI application visit Abacus UI

Scripting Reference

Datatypes

The following data types are supported:

Name Note
Integer Any integer constant without a decimal place
Float Any number constant written with a decimal place
Array A list of values of the same type surrounded by []
Map A dictionary of key value pairs
Boolean True and false constants
Series An array used for fast calculations
Dataframe A map of series used for fast calculations
String An array of characters, uses double quotes
Char A single character, uses single quotes

Everything is an expression

Everything can be evaulated as an experession. This means variables can be set to if blocks, loops, or anything else;

let x = if y == "test" { 1 } else { 2 };

Returning output

Output is rendered based on the returned value of a block. The final value of the block is automatically returned. The return keyword is only needed if an early return is preferable.

if x == 0 {
	return 0;
}

if x > 10 {
	// note the lack of a semicolon here
	x / 5
} else {
	// note the lack of a semicolon here
	x / 10
}

Variables

Variables can be assigned using the let keyword. Variables are dynamically typed and globally mutable:

let pulse_rate = 0.8;
let time = 3.2;

time / pulse_rate

Functions

Functions can be defined using the fn keyword. Return types and arguments are dynamic and do not require typing.

fn add_one(x) {
	x + 1;
}

add_one(2)

Object maps

Dictionary style data maps are possible and can be index or accessed by a property notation. Dictionaries are defined using a special syntax wrapper: #{}.

let account = #{ first_name: "Alice", last_name: "Allison", balance: 150.32 };
// Access via property notation
account.balance += 10;
// Access via indexing
account["last_name"] = "Test";
account

Series

A series provides a powerful way to perform calculations on an array of data. Operations performedon the series are performed against all of its member values. Serieses are constructed using the series fucntion and passing an array of values.

let s = series([1,2,3,4]);
// Return an array of values calculated from the series
[ s + 10, s * s ]

Dataframes

Dataframes provide an object for working with tabular data made up of several series. Dataframes are initialzied using the dataframe constructor function and passing in an object map container name/array pairs.

Dataframe series can be accessed via indexing or property notation just like object maps.

let df = dataframe(#{
	name: ["Alice", "Bob", "Charles"],
	rate: [18,20,20],
	hours: [22,40,55]
});
df.balance = df.rate * df.hours;
df

Filtering

Dataframes are more powerful than object maps and can be filtered. Filtering requires two parts:

  1. Selecting the columns to be included
  2. providing a predicate to filter a column's value The filtering syntax is FROM <dataframe> <column array> : <array of predicates>

Predicates consist of a quoted name for the series/column an operator and a value. Valid operators are: gt, gte, lt, lte.

Filtering returns a new dataframe with the extracted values.

let df = dataframe(#{
	name: ["Alice", "Bob", "Charles"],
	rate: [18,20,20],
	hours: [22,40,55]
});
let high_rates = from df ["name", "rate", "hours"] : ["rate" gte 20];
high_rates.balance = high_rates.rate * high_rates.hours;
high_rates