Skip to content

Clear

Name Mandatory Description Default Type
⬅️ Input Any input is ignored. Any
Output ➡️ The input 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

Clears all elements from the sequence or table passed to it. Applicable only to sequences and tables. For sequences, this operation is very fast as Shards recycles memory extensively. If the variable does not exist or the type is not a sequence or table, it simply passes through without failing.

Details

Clear removes all the elements of the sequence that has been passed to it in the :Name parameter.

This shard works on both sequences and tables. Parameter :Key applies only to tables.

Since variables may be locally scoped (created with (:Global false); exists only for current wire) or globally scoped (created with (:Global true); exists for all wires of that mesh), both parameters :Global and :Name are used in combination to identify the correct variable to clear.

Any input to this shard is ignored and instead passed through as its output.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[1 2 3] >= seq                     ; create local sequence
[4 5 6] | Set(seq-global Global: true)  ; create global sequence with different name
Get(seq) | Log                        ; read local sequence  => [1, 2, 3]
Get(seq-global Global: true) | Log    ; read global sequence => [4, 5, 6]

; clear local sequence
Clear(Name: seq)                      ; clear local sequence
Get(seq) | Log                        ; local sequence cleared => []  
Get(seq-global Global: true) | Log    ; global sequence intact => [4, 5, 6]  
100 | AppendTo(seq)                   ; append something to local sequence
Get(seq) | Log                        ; local sequence no more empty => [100]

; clear the global sequence
Clear(Name: seq-global Global: true)  ; clear global sequence
Get(seq-global Global: true) | Log    ; global sequence cleared => []
Get(seq) | Log                        ; local sequence intact => [100]

[info] [sample-wire] [1 2 3]
[info] [sample-wire] [4 5 6]
[info] [sample-wire] []
[info] [sample-wire] [4 5 6]
[info] [sample-wire] [100]
[info] [sample-wire] []
[info] [sample-wire] [100]