Skip to content

Const

Name - Description Default Type
<input> Any input is ignored.
<output> The declared constant value. Any
Value The constant value to insert in the wire. None Any

Declares an un-named constant value (of any data type).

Details

Const declares a constant value (of any data type) by passing it into the parameter :Value. Such a value is usually declared for use as input in other shards.

A constant value declared with Const is un-named i.e., it is not assigned to any variable or allocated any alias. Hence it cannot be invoked or referred to later. To create named constants see Ref.

You can even skip this shard and pass the constant value directly but internally it will be translated to a Constshard that outputs this constant value. However, it's good practice to use this keyword in while passing constants in Shards programs.

You can also use (Const nil) to overwrite/nullify (since nil stands for null data) the input to the subsequent shard, if required (see the last code sample).

Input field is ignored and the output of this shard is the constant value defined by it.

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
24
;; declare an int with `Const` and consume in `Math.Multiply`
(Const :Value 2) 
(Math.Multiply 4) (Log)         ;; => 8

;; declare an int without `Const` and consume in `Math.Multiply`
2 (Math.Multiply 4) (Log)       ;; => 8

;; declare a string with `Const`
(Const "Hello World!") (Log)    ;; => "Hello World!"

;; declare a sequence with `Const`
(Const ["A" "B" "C"]) (Log)     ;; => ["A" "B" "C"]

;; declare a Float4 with `Const`
(Const (Float4 1 2 3 4)) (Log)  ;; => (Float4 1 2 3 4)

;; declare a table with `Const`
(Const {"key1" 10 "key2" 20.0})
(Log)                           ;; => {"key1" 10 "key2" 20.0}

;; nullifying the input to a shard with (Const nil)
"Hello World"                   ;; string input for Log
(Const nil)                     ;; nulls the string input
(Log)                           ;; Log gets no input => None
[info] [shards/General/Const/Const.edn] 8
[info] [shards/General/Const/Const.edn] 8
[info] [shards/General/Const/Const.edn] Hello World!
[info] [shards/General/Const/Const.edn] [A B C]
[info] [shards/General/Const/Const.edn] (1 2 3 4)
[info] [shards/General/Const/Const.edn] {key1: 10 key2: 20}
[info] [shards/General/Const/Const.edn] None