Discover the basics of the WarpScript language, the component making Warp 10 the Most Advanced Time Series Platform.
WarpScript is undoubtedly what makes Warp 10 the Most Advanced Time Series Platform. It is the data programming language created specifically for analyzing time series data.
What is WarpScript?
The goal of WarpScript is to make you more efficient when you work with time series. It brings you functions that take care of many details. So you can focus on the business problems you are trying to solve. This efficiency comes quite rapidly. But as with all new technology, there is an initial apprehension which you need to overcome.
The goal of WarpScript is to make you more efficient when you work with time series. Share on XThis apprehension is actually twofold, and more often than not, people tend to mix its two aspects. The first thing that is disturbing is actually working with time series. You have to bend your mind to reason in a matricial way, with time flowing in one direction and your multiple series in the other. The second thing is the intimidating number of functions (more than 1000) that WarpScript has to offer. And its syntax may differ from what you have seen before if you have never used a concatenative programming language.
The basics
Now that this scary name has been dropped, let me teach you the basics of WarpScript, so you feel comfortable putting it to work on your own problems involving time series.
Put in simple terms, a concatenative language is one in which each term (think word), is a function. Two consecutive words is a composition of two functions. Functions may consume arguments and produce outputs. WarpScript, as other similar languages, like FORTH, PostScript, or Bitcoin's Script, uses postfix notation, meaning that the function name appears after its arguments. So if you have used a language where the syntax for a function call is
F(a,b,c,d);
The same function call in WarpScript would be written as
$a $b $c $d F
The dollar sign retrieves the content of the variable name it precedes. Functions in WarpScript can produce multiple values as their output, the easiest way to deal with those values is to store them in variables. To store values in variables, simply call the STORE function with the list of variables to set and their values as parameters. So for example if the above F function produces two values as outputs, and you want to store them in variables x and y, you would use the following WarpScript code:
$a $b $c $d F [ 'x' 'y' ] STORE
The [ … ] syntax creates a list, here with two strings "x" and "y". After the STORE function is called, you can retrieve the content of variables x and y using $x and $y.
Literals such as integer and floating-point numbers or strings can be considered special functions that produce themselves as output. So your WarpScript code is simply a succession of function calls with variable manipulations before (dereference) and after (storage).
Learn more about Time Series: the future of data |
The macros
One final concept we will cover is that of macros. A macro is like an anonymous function, it helps simplify your code by factoring a chain of function calls that you reuse often. Macros are first-class objects in WarpScript, meaning that you can store them in variables and use them as parameters to functions. The syntax for defining a macro and storing it in a "macro" variable is simple:
<%
[ 'a' 'b' ] STORE
42 3.1415 $a $b F // Computes F(42,3.1415,$a,$b)
G H // Computes H(G(F(42,3.1415,$a,$b))
%> 'macro' STORE
The above macro will store its two parameters in variables "a" and "b" and then use them as parameters for a call to function F followed by composition with functions G and H. The result of this composition call is the output of the macro.
The above code is equivalent to the following closure using a prefix notation:
macro = (a,b) -> { H(G(F(42, 3.1415, a, b))); };
We will stop here for now…
As you write your first WarpScript code you will gradually understand better the underlying concepts. You will sooner than later start doing more complex things in WarpScript.
Keep on reading with this tutorial using a Tropical Cyclones dataset, and explore the documentation.
Don't hesitate to ask questions on the Warp 10 Google Group, on Slack, or on Twitter. The team at SenX building the platform will jump in and help you.
Happy coding.
Read more
Digital Twins, a requirement for Industrial AI
Données de santé : sortir de l’impasse
Mobilité et données : un train de retard pour la loi LOM
Co-Founder & Chief Technology Officer