Skip to content

Ref

Name Mandatory Description Default Type
⬅️ Input The value to be set to the variable. Any
Output ➡️ The input value is passed through as the output. Any
Name No The name of the variable. `` StringVar(Any)
Key No The key of the value to read from the table (parameter applicable only if the target variable is a table). none Any
Global No If the variable is available to all of the wires in the same mesh. false Bool
Overwrite No If the variable should be overwritten if it already exists. false Bool

Creates an immutable reference variable. Once created this variable cannot be changed.

Details

Ref creates an immutable variable and assigns a constant value to it. Once created this variable cannot be changed.

The name of the variable comes from the :Name parameter and the constant value comes from the input. The type of input controls the kind of variable that will created: numeric input creates numeric variable, string input creates string variable, and sequence input would create a sequence variable.

To create a table variable, along with the input, you also have to pass the key in the :Key parameter. In this case the input (whatever it may be - numeric, string, sequence) becomes the value of the key that was passed in parameter :Key.

The :Global parameter controls whether the created variables can be referenced across wires (:Global set to true) or only within the current wire (:Global set to false, default behaviour).

The input to this shard is used as the value for the new variable and is also passed through as this shard's output.

Note

Ref has two aliases: = and &>. Both are aliases for (Ref ... :Global false). See the code examples at the end to understand how these aliases are used.

See also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; create an immutable string variable (by default available only to current wire)
"Hello" | Ref(Name: svar)
svar | Log(".svar") ; => .svar: Hello
; uncomment next line to see the immutable-variable-update error
; 20 | Update(svar)
; => Error composing shard: Set/Ref/Update, attempted to write an immutable variable.

; create an immutable numeric variable (available to all wires because Global: true)
100 | Ref(Name: nvar Global: true)
nvar | Log(".nvar") ; => .nvar: 100

; create an immutable sequence
[10 20] | Ref(Name: seq)
seq | Log(".seq") ; => .seq: [10, 20]

; create an immutable table
["a" "b"] | Ref(Name: "table" Key: "key1")
table | Log(".table") ; => .table: {key1: [a, b]}

; Using Ref aliases
; = is alias for Ref(Global: false): create an immutable string variable: 
"World" = svarA
svarA | Log(".svarA")

[info] [sample-wire] .svar: Hello
[info] [sample-wire] .nvar: 100
[info] [sample-wire] .seq: [10 20]
[info] [sample-wire] .table: {key1: [a b]}
[info] [sample-wire] .svarA: World