FLoWS vs WarpScript

This tutorial is for you if you already know WarpScript. It will help you to spot differences, and to make a smooth transition to FLoWS if you wish to.

Using FLoWS inside WarpScript

FLoWS has no dedicated endpoint in Warp 10 yet. It is packaged as an extension that provides the FLOWS function. The FLOWS function takes a STRING containing the FLoWS code to execute as input. Wrap your FLoWS code into a WarpScript multiline string, then call FLOWS. All the tooling (WarpStudio, VSCode extension) do this wrapping for you.

The FLOWS function executes the FLoWS code in an execution environment identical to that of WarpScript, there is no prior conversion to WarpScript code though. Your FLoWS code can nevertheless be transpiled into WarpScript code via the use of the FLOWS-> function.

Using the same execution environment means your FLoWS scripts share all the already defined variables, WarpScript macros, bootstrap scripts, redefined functions.

// This is WarpScript 2 'c' STORE 'hello' // let this on the stack 1 'var' STORE // this will be overriden by FLOWS <' a=22 b=-1 var=100 return (a+b)*c '> FLOWS $var // this will be 100

Running FLoWS inside WarpScript is safe, but FLOWS does not perform a context backup/restore: FLoWS can alter WarpScript variables.

Using WarpScript inside FLoWS

In WarpScript, you can run WarpScript from WarpScript with the EVAL function. EVAL is also available in FLoWS, so you can run WarpScript within FLoWS.

Running WarpScript inside FLoWS can be risky: Be careful with stack manipulation and what you leave on the stack.

// This is FLoWS a=40 b=2 c=EVAL(" $a $b + PI 'var' STORE ") return c,var

What you cannot do in FLoWS

  • You should not use stack manipulation functions (DUP, DROP, ROT...). It is not forbidden, but it can lead to unexpected errors. As FLoWS always leaves the stack empty after statements, you do not need these functions.
  • The only collection type you cannot write explicitly in FLoWS is WarpScript SET. A set is a collection of unique objects. SET objects can only be created from a list with the help of the ->SET function. See example below.
// This is WarpScript ( 5 2 1 ) ( 2 1 8 ) UNION <' return UNION(->SET([5,2,1]),->SET([2,1,8])) '> FLOWS

FLoWS cost

FLoWS is simpler to learn, read and maintain. It comes with a small performance hit: FLoWS takes extra precautions to ensure the execution environment (the infamous stack) is kept clean and enforces strict checks on parameter and return value count. So... They are some extra functions called behind the scene. You can roughly check what is done by looking at the WarpScript equivalent of your FLoWS code via the FLOWS-> function:

// This is WarpScript <' a=22 b=-1 var=100 return (a+b)*c '> FLOWS-> // convert into indented, readable WarpScript.

These extra functions are fast to execute, but it still is a small CPU overhead.