Virtel 4 Beta Larix! Rewrited to Rust. Yet very unstable.

Download

Variables and Lists

Creating and Managing Variables

Objective: Create and manipulate variables to store and retrieve data.

Steps:
  • Create a variable:
    var set "Hello" greeting;
    • "Hello" is the value to store.
    • "greeting" is the variable name.
  • Get a variable:
    var get "greeting" message;
    • "greeting" is the variable to retrieve.
    • "message" is the new variable to store the value.
  • Display the variable:
    csl write message;

Working with Lists

Objective: Create and manipulate lists to work with data collections.

Steps:
  • Create a new list:
    lst new myList;
    • "myList" is the name of the list.
  • Add items to the list:
    lst set myList "0" "apple"; lst set myList "1" "banana";
    • "0" and "1" are the indices.
    • "apple" and "banana" are the values.
  • Get an item:
    lst get myList "0" fruit; csl write fruit;

Practical Example

Objective: Create a list of fruits and retrieve the first item.

Steps:
  • Create a list of fruits:
    lst new fruits; lst set fruits "0" "orange"; lst set fruits "1" "grape";
  • Get and display the first fruit:
    lst get fruits "0" firstFruit; csl write firstFruit;

Tips

  • Use clear variable and list names for better readability.
  • Remember that lists are zero-indexed.
  • Delete unused variables and lists to free up resources.

Conclusion

Variables and lists are the foundation for data storage and management in Virtel Steps. Use commands like var set, var get, lst new, and lst set to efficiently work with data.

Commands

var set

Sets a value to a new variable.

var set (value) (newVarName)
  • value: The value to set (type: VAR).
  • newVarName: The name of the new variable (type: VAR).
var set "Hello" greeting; csl write greeting;

This example sets "Hello" to "greeting" and prints it to the console.

var get

Gets the value of a variable whose name is stored in another variable and stores it in a new variable.

var get (valueVarName) (newVarName)
  • valueVarName: The variable containing the name of the target variable (type: VAR).
  • newVarName: The name of the new variable to store the retrieved value (type: VAR).
var set "Hello" greeting; var set "greeting" varName; var get varName retrievedValue; csl write retrievedValue;

This example retrieves "Hello" from "greeting" via "varName" and prints it.

var del

Deletes a variable from the store.

var del (newVarName)
  • newVarName: The name of the variable to delete (type: VAR).
var set "Hello" greeting; var del "greeting";

This example deletes the "greeting" variable from the store.

var import

Imports a variable from another flow into the current flow.

var import (valueFlowName) (varName)
  • valueFlowName: The name of the flow to import from (type: VAR).
  • varName: The name of the variable to import (type: VAR).
var import "flow-1" sharedVar; csl write sharedVar;

This example imports "sharedVar" from "flow-1" and prints its value.

var export

Exports a variable from the current flow to another flow.

var export (valueFlowName) (varName)
  • valueFlowName: The name of the flow to export to (type: VAR).
  • varName: The name of the variable to export (type: VAR).
var set "Hello" sharedVar; var export "flow-1" sharedVar;

This example exports "sharedVar" with value "Hello" to "flow-1".

var list

Converts a JSON string into a list and stores it in a new list variable.

var list (varName) (newListVarName)
  • varName: The variable containing the JSON string (type: VAR).
  • newListVarName: The name of the new list variable to store the parsed list (type: LIST).
var set "[\"a\", \"b\"]" jsonString; var list jsonString parsedList; lst get parsedList "0" firstItem; csl write firstItem;

This example converts "[\"a\", \"b\"]" into a list and prints "a" from it.

lst new

Creates a new empty list.

lst new (lstName)
  • lstName: The name of the new list (type: LIST).
lst new myList; lst set myList "0" "item1";

This example creates an empty list "myList" and adds "item1" at index 0.

lst set

Sets a value at a specific index in a list (inserts the value at that position).

lst set (lstName) (index) (value)
  • lstName: The name of the list (type: LIST).
  • index: The index where the value will be inserted (type: VAR).
  • value: The value to insert (type: VAR).
lst new myList; lst set myList "0" "apple"; lst set myList "1" "banana";

This example creates a list and sets "apple" at index 0 and "banana" at index 1.

lst get

Gets a value from a list at a specific index and stores it in a new variable.

lst get (lstName) (index) (newVarName)
  • lstName: The name of the list (type: LIST).
  • index: The index of the value to retrieve (type: VAR).
  • newVarName: The name of the new variable to store the value (type: VAR).
lst new myList; lst set myList "0" "apple"; lst get myList "0" fruit; csl write fruit;

This example retrieves "apple" from "myList" at index 0 and prints it.

lst del

Deletes an element from a list at a specific index.

lst del (lstName) (index)
  • lstName: The name of the list (type: LIST).
  • index: The index of the element to delete (type: VAR).
lst new myList; lst set myList "0" "apple"; lst del myList "0";

This example creates a list, adds "apple", and then deletes it from index 0.

lst len

Gets the length of a list (number of elements) and stores it in a new variable.

lst len (lstName) (newVarName)
  • lstName: The name of the list (type: LIST).
  • newVarName: The name of the new variable to store the length (type: VAR).
lst new myList; lst set myList "0" "apple"; lst len myList length; csl write length;

This example creates a list with one item and prints its length ("1").

lst var

Converts a list into a JSON string and stores it in a new variable.

lst var (lstName) (newVarName)
  • lstName: The name of the list (type: LIST).
  • newVarName: The name of the new variable to store the JSON string (type: VAR).
lst new myList; lst set myList "0" "apple"; lst var myList jsonString; csl write jsonString;

This example converts a list with "apple" into a JSON string (e.g., "[\"apple\"]") and prints it.

lst import

Imports a list from another flow into the current flow.

lst import (valueFlowName) (varName)
  • valueFlowName: The name of the flow to import from (type: VAR).
  • varName: The name of the list to import (type: LIST).
lst import "flow-1" sharedList; lst get sharedList "0" item; csl write item;

This example imports "sharedList" from "flow-1" and prints its first item.

lst export

Exports a list from the current flow to another flow.

lst export (valueFlowName) (varName)
  • valueFlowName: The name of the flow to export to (type: VAR).
  • varName: The name of the list to export (type: LIST).
lst new myList; lst set myList "0" "apple"; lst export "flow-1" myList;

This example exports "myList" with "apple" to "flow-1".

ref set

Creates a reference to a variable by storing its name in a new variable of type REF.

ref set (varName) (newRefName)
  • varName: The name of the variable to reference (type: VAR).
  • newRefName: The name of the new reference variable (type: REF).
var set "Hello" greeting; ref set "greeting" myRef;

This example creates a reference to the "greeting" variable, storing it in "myRef".

ref name

Creates a reference to a variable name stored in another variable.

ref name (valueVarName) (newRefName)
  • valueVarName: The variable containing the name of the target variable (type: VAR).
  • newRefName: The name of the new reference variable (type: REF).
var set "targetVar" varName; ref name "varName" myRef;

This example creates a reference to "targetVar" (stored in "varName") in "myRef".

ref get

Gets the name of the variable pointed to by a reference (not its value).

ref get (newRefName)
  • newRefName: The name of the reference variable (type: REF).
var set "Hello" greeting; ref set "greeting" myRef; ref get myRef;

This example retrieves "greeting" from "myRef" (returns the variable name, not "Hello").

ref del

Deletes a reference from the store.

ref del (newRefName)
  • newRefName: The name of the reference to delete (type: REF).
ref set "greeting" myRef; ref del "myRef";

This example deletes the reference "myRef" from the store.