Skip to content

Get

Name - Description Default Type
<input> Any input is ignored.
<output> The output is the value read from the variable. Any
Name The name of the variable. "" String&Any
Key The key of the value to read from the table (parameter applicable only if the target variable is a table). None String&String
Global If the variable is available to all of the wires in the same mesh. false Bool
Default The default value to use to infer types and output if the variable is not set, key is not there and/or type mismatches. None Any

Reads the value of the variable passed to it.

Details

Getis used read the value of an existing variable. All sorts of variables that can be created by Set, can be read by Get.

The :Name parameter should contain the name of the variable that's being read. If the variable is a string/numeric variable or a sequence it will be read directly. But for a table to be read its key should be passed in the parameter :Key. This will allow Get to access the particular key in the table and read it's value.

The :Default parameter specifies a value to return in case the variable being read doesn't yeild a valid value, or the sequence is malformed, or the required key is missing from the table, etc. This allows the program to continue processing even if some expected data is missing.

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 read.

Any input to this shard is ignored and its output contains the value of the variable read by Get.

Note

Get has an alias ??. This symbol represents the logical operator OR. Hence, ?? functions as an alias for Get with a default value. For example, .var1 ?? 40 means .var1 or 40 and this is effectively an alias for (Get .var1 :Default 40). See the code examples at the end to understand how this alias is used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;; create a mutable string variable and get its value
"Hello" (Set :Name .svar)           ;; set value
(Get :Name .svar) >= .gotSvar       ;; get value and store it
.gotSvar (Log "gotten value")       ;; => gotten value: Hello

;; create an immutable numeric variable and get its value
100 (Ref :Name .nvar)               ;; set value
(Get :Name .nvar) >= .gotNvar       ;; modify numeric variable
.gotNvar (Log "gotten value")       ;; => gotten value: 100

;; create a mutable sequence and get it
[10 20 30] (Set :Name .sequence)
(Get .sequence) (Log)               ;; => [10, 20, 30]

;; create an empty sequence and try reading it with the :Default failsafe
[] (Set :Name .seqEmpty)
(Get .seqEmpty
    :Default "Void") (Log)          ;; => Void

;; create a table and get one of it's key-values pairs
["a" "b"] (Set :Name "table" :Key "key1")
(Get .table :Key "key1") (Log)      ;; => [a, b]

;; create a table and try to get a non-existent key-value using the :Default parameter
["a" "b"] (Set :Name "table" :Key "key1")
(Get .table 
    :Key "key2"
    :Default "Key missing") (Log)   ;; => "Key missing"

;; Using a `Get` alias

;; `??` is `OR` hence alias for `(Get :Default ...)`
;; try getting a non-existent key-value again
["a" "b"] (Set :Name .tableA :Key "key1")
(Get .tableA :Key "key2") ?? "Key still missing"
(Log)                               ;; => "Key still missing"

;; create mutable local/global variables and get their values
"Local" (Set .str)                 ;; create local variable
"Global" (Set .str :Global true)   ;; create same-name global variable
(Get .str) (Log)                   ;; get local variable => "Local"
(Get .str :Global true) (Log)      ;; get same-name global variable => "Global"
[info] Set - Warning: setting an already exposed variable "str", use Update to avoid this warning.
[info] [shards/General/Get/Get.edn] gotten value: Hello
[info] [shards/General/Get/Get.edn] gotten value: 100
[info] [shards/General/Get/Get.edn] [10 20 30]
[warning] Get found a variable but it's using the default value because the type found did not match with the default type.
[info] [shards/General/Get/Get.edn] Void
[info] [shards/General/Get/Get.edn] [a b]
[info] [shards/General/Get/Get.edn] Key missing
[info] [shards/General/Get/Get.edn] Key still missing
[info] [shards/General/Get/Get.edn] Local
[info] [shards/General/Get/Get.edn] Global