FLoWS Basics

The syntax error will be raised before the RENAME error. Fix the syntax errors in the upper code, and try again: The RENAME runtime error should be caught, and the script returns empty GTS.

FLoWS precedence errors

g = NEWGTS() TRY( () => { g = RENAME(g, 'raw_temperature') g = ADDVALUE(g,NOW(),0.0,0.0,0,42) g = RELABEL(g,{'unit':'°C'}) gf = 32 + g * 9 / 5
gf = RELABEL(gf,{'unit':'°Fahrenheit'}) }, () => { g=NEWGTS() gf=NEWGTS()  }, () => { } ) return g, gf

Does 42°C equals to 133°F? No… It should be 107.6.

FLoWS implements a simple left to right precedence, there is no operator priority.

As you may have done in the C language in the past, the best practice is to explicit the priority with parentheses (remember MISRA C R.12.1). Moreover, the GTS type is LONG. The operations will be integer, not floating point ones: 9 divided by 8 equals 1 instead of 1.8. You must write 9.0 to force type conversion. The correct code is:

g = NEWGTS() TRY( () => { g = RENAME(g, 'raw_temperature') g = ADDVALUE(g,NOW(),0.0,0.0,0,42) g = RELABEL(g,{'unit':'°C'}) gf = 32 + (g * (9.0 / 5))
gf = RELABEL(gf,{'unit':'°Fahrenheit'}) }, () => { g=NEWGTS() gf=NEWGTS()  }, () => { } ) return g, gf

Objects

In FLoWS, there are a few primitives (number, strings, boolean) and lots of object: object types are the same as in WarpScript.

Type Use Case
BITSET Used for binary operation (decode a CAN bus frame for example)
BOOLEAN
BYTES Bytes array, raw binary data storage
COUNTER Atomic long.
DOUBLE
GEOSHAPE Polygon drawing on earth
GTS
LIST
LONG
MACRO
MAP
MAPPER Piece of custom Warpscript
MATRIX Math matrix
NULL
PFONT Font object. Linked to Pgraphics.
PGRAPHICS Pgraphics Image object. Could be rendered to png.
PIMAGE Pgraphics layer object.
PSHAPE Pgraphics shape object
REDUCER Piece of custom Warpscript
SET A collection of unique values
STRING
VECTOR Math vector
VLIST Vector, used for example to produce data bags in Pig

The bold ones can be represented in the JSON stack output.

The other objects types cannot be serialized in JSON: it means if you try to return them at the end of your FLoWS script, you will get null in the JSON object.

For example, run this code, and check the JSON tab output:

myImage = PGraphics(200, 300, '2D3') // new image, size 200x300, with antialiasing PtextSize(myImage, 20) Pfill(myImage, 0xffff0000) //red Ptext(myImage, 'Warp 10', 10, 20) return myImage, TYPEOF(myImage)

The PGRAPHICS objects cannot be serialized. They need to be converted into a PNG image, like in the code below. You can see the image in the image tab.

myImage = PGraphics(300, 200, '2D3') // new image, size 300x200, with antialiasing PtextSize(myImage, 20) Pfill(myImage, 0xffff0000) //red Ptext(myImage, 'Warp 10', 10, 20) return Pencode(myImage)

The conversion table is the same.

FLoWS make function arguments and results far more explicit than WarpScript. But as WarpLib is the same behind, some objects are mutable. For example, renaming a GTS does not change the GTS object:

g = NEWGTS() g = RENAME(g, 'raw_temperature') g = ADDVALUE(g,NOW(),0.0,0.0,0,42) g = RELABEL(g,{'unit':'°C'}) h = RELABEL(g,{'unit':'°Fahrenheit'}) // h is not a copy h = RENAME(h, 'US_temperature') return g, h

In this example, g and h refer to the same object. Lots of functions in WarpLib return the input object reference. FLoWS won't bother if you ignore the return value:

g = NEWGTS() g = RENAME(g, 'raw_temperature') g = ADDVALUE(g,NOW(),0.0,0.0,0,42) RELABEL(g,{'unit':'°C'}) return g

Next Step

FLoWS is a WarpScript extension, so you now need to undestand the link between FLoWS and WarpScript with the next tutorial.


Explore FLoWS tutorials and blog posts on the blog

Found an issue on this page or something missing?

Tell us onSlack iconThe Lounge, the Warp 10 Community Slack.