Axon Flashcards
Axon Overview
Axon is a programming language used for scripting within SkySpark. Most functionality can be accessed through Axon:
- query Folio tag database
- perform data transformations such as rollups and normalizations
- creating your own function libraries
- rules for the spark engine are written in Axon
- create custom reports for Report App
- create scripts for data import
- create background jobs for data synchronization and maintenance
One of the pivotal features of SkySpark is that all queries to the database/analytics engine are full Axon expressions:
// find all the records with kw tag
kw
// same as above
readAll(kw)
// find all recs with kw and read history data for yesterday readAll(kw).hisRead(yesterday)
// find peak kW for yesterday for all kw recs readAll(kw).hisRead(yesterday).hisRollup(max, 1day)
This design allows great flexibility scaling up from simple queries to powerful data transformation pipelines - all using a single general purpose syntax.
Language Overview
Axon is a full general purpose programming language characterized as follows:
- simple: the language syntax is minimal and designed to be fully learned in a single session
- functional: everything is a function (the language is not object oriented); closures are heavily used by the language and the library to concisely express data transformations
- dynamic typing: you do not declare types for variables
- tag oriented: the language is designed to work in conjunction with the Folio database tag model
- time-series oriented: the language has dedicated syntax and a rich library of functions for working with time series data such as time, date, and date range literals
- unit oriented: all numbers in Axon and Folio can be annotated with an explicit unit of measurement which is checked and carried through during arithmetic
Axon draws inspiration from Fantom, Lisp, Ruby, Scala, and Haskell. Experienced programmers should be able to pick up Axon very quickly, however, a grounding in functional programming will definitely help.
The Axon Language chapter digs into the syntax of the Axon language.
Func Recs
Function records define new top-level functions with the following tags:
- name: programmatic name of the function
- func: marker tag to indicate function
- src: Axon source code for function stored as text/plain bin
Top-Level Namespace
The top-level namespace of a project is defined by:
- core functions
- named func records
- extensions installed by the project
The following functions are useful for working with the top-level function namespace:
- funcs: list or match functions defined in the top-level namespace
- func: resolve a function in the top-level namespace
Qualified Names
The name used in a function call can be either qualified or unqualified. Qualified functions specify an explicit library namespace using double colons:
site: :toPoints // qualified in “site” ext namespace
core: :toHex // core functions live in “core” namespace
Unqualified function names are resolved by the implicit namespace which is searched in this order:
- local namespace of function (parameter/variable names)
- core function namespace
- named func records
- extensions installed by project
Function Overrides
You can override an extension function by declaring a function record with the same name. Functions resolved in the project take priority over functions defined by extensions. Note you cannot override a core function. You can access the built-in function in your override using its qualified name:
geoTz(val) => do
// handle special case
if (val[“geoCountry”] == “RU”) return “Moscow”
// route back to built-in version
return geo::geoTz(val)
end
Math Operators
Addition
=== Addition === num + num \>\> num date + num \>\> date (num must be number of days) dateTime + num \>\> dateTime (num must have duration unit) dateRange + num \>\> dateRange (num must have duration unit) uri + str \>\> uri concat uri + uri \>\> uri concat str + obj \>\> str concat obj + str \>\> str concat
Math Operators Subtraction
=== Subtraction === num - num \>\> num date - num \>\> date (duration must be number of days) date - date \>\> num (difference in number of days) dateTime - num \>\> dateTime (num must have duration unit) dateTime - dateTime \>\> num (difference in number of hours) dateRange - num \>\> dateRange (num must have duration unit)
Math Operators Multiplication
=== Multiplication ===
num * num >> num
Math Operators Division
=== Division ===
num / num >> num
Get and Trap Operators
The indexing operator target[key]
is a shortcut for the get
function. It can be used to index strings, lists, dicts, and grids:
str [index]
get unicode char from string
str[start..end]
slice/substring
list[index]
get an item at zero based index
dict[key]
lookup tag value by key