A gentle introduction to WarpScript™

WarpScript by SenX

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.

The goal of WarpScript is to make you more efficient when you work with time series, bringing 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.

This 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, because 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 (close to 900) that WarpScript has to offer and its syntax which may differ from what you have seen before if you have never used a concatenative programming language.

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 langages, like FORTH, PostScript or Bitcoin’s Script, uses a 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 which produce themselves as output.  So your WarpScript code is simply a succession of function calls with variable manipulations before (dereference) and after (storage).

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 a 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 and will sooner than later start doing more complex things in WarpScript. Don’t hesitate to ask questions on the Warp 10 Google Group, or our Sprectrum Channel, the community of users and the team at SenX building the platform will jump in and help you.

Happy coding.

Share