You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/language/glossary.mdx
+57-53Lines changed: 57 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,13 @@ title: Glossary
3
3
sidebar_position: 26
4
4
---
5
5
6
+
This glossary provides clear explanations and code examples for the most important symbols and operators in Cadence. Each entry describes the symbol's purpose, usage, and common scenarios, helping both new and experienced developers quickly understand Cadence syntax.
7
+
8
+
Use this guide as a handy reference to navigate Cadence's unique features and operator behaviors.
6
9
7
10
:::tip
8
11
9
-
Tip: <kbd>CTRL</kbd>/<kbd>⌘</kbd> + <kbd>F</kbd> and type in the symbol or operator you want to look up.
12
+
To search for a term, press <kbd>CTRL</kbd>/<kbd>⌘</kbd> + <kbd>F</kbd> and type in the symbol or operator you want to look up.
10
13
11
14
:::
12
15
@@ -16,27 +19,25 @@ The `&` (ampersand) symbol has several uses.
16
19
17
20
### Reference
18
21
19
-
If an expression starts with the `&` (ampersand) symbol, it creates a [reference](./references.mdx).
22
+
If an expression starts with the `&` (ampersand) symbol, it creates a [reference].
20
23
21
24
```cadence
22
25
let a: String = "hello"
23
26
let refOfA: &String = &a as &String
24
27
```
25
28
26
-
References may also be authorized if the `&` symbol is preceded by `auth` (otherwise the reference is unauthorized).
29
+
References may also be authorized if the `&` symbol is preceded by `auth`. Otherwise, the reference is unauthorized.
27
30
28
-
Authorized references have the `auth` modifier, along with the set of entitlements to which the reference is authorized,
29
-
i.e. the full syntax is `auth(E, F) &T`, whereas unauthorized references do not have a modifier.
31
+
Authorized references have the `auth` modifier, along with the set of entitlements to which the reference is authorized (i.e., the full syntax is `auth(E, F) &T`, whereas unauthorized references do not have a modifier).
30
32
31
33
```cadence
32
34
let a: String = "hello"
33
35
let refOfA: auth(X) &String = &a as auth(X) &String
34
36
```
35
37
36
-
### Logical Operator
38
+
### Logical operator
37
39
38
-
It can be also used as a [logical operator (AND)](./operators/arithmetic-logical-operators.md#logical-operators),
39
-
by appearing twice in succession (i.e. `&&`):
40
+
The `&` (ampersand) symbol can be also used as a [logical operator (AND)], by appearing twice in succession (i.e., `&&`):
40
41
41
42
```cadence
42
43
let a = true
@@ -47,11 +48,9 @@ let c = a && b // false
47
48
48
49
## `@` (at)
49
50
50
-
The `@` (at) symbol before a type is used to annotate whether the type is a [resource](./resources.mdx).
51
+
The `@` (at) symbol before a type is used to annotate whether the type is a [resource].
51
52
52
-
The `@` symbol must appear at the beginning of the type, not inside.
53
-
For example, an array of `NFT`s is `@[NFT]`, not `[@NFT]`.
54
-
This emphasizes the whole type acts like a resource.
53
+
The `@` symbol must appear at the beginning of the type, not inside. For example, an array of `NFT`s is `@[NFT]`, not `[@NFT]`. This emphasizes that the whole type acts like a resource.
55
54
56
55
```cadence
57
56
// Declare a resource named `SomeResource`
@@ -69,7 +68,7 @@ resource SomeResource {
69
68
// we use the '@' symbol to reference a resource type
70
69
let a: @SomeResource <- create SomeResource(value: 0)
71
70
72
-
// also in functions declarations
71
+
// also in function declarations
73
72
access(all)
74
73
fun use(resource: @SomeResource) {
75
74
destroy resource
@@ -80,7 +79,7 @@ fun use(resource: @SomeResource) {
80
79
81
80
The `:` (colon) symbol has several uses.
82
81
83
-
### Type Declaration
82
+
### Type declaration
84
83
85
84
If a `:` (colon) follows a variable/constant/function declaration, it is used to declare its type.
86
85
@@ -94,10 +93,9 @@ fun addOne(x: Int): Int { // return type of Int
94
93
}
95
94
```
96
95
97
-
### Ternary Conditional Operator
96
+
### Ternary conditional operator
98
97
99
-
The `:` (colon) is also be used in [ternary operations](./operators/bitwise-ternary-operators.md#ternary-conditional-operator) to represent the "otherwise" section,
100
-
such as the following:
98
+
The `:` (colon) can also be used in [ternary operations] to represent the "otherwise" section, such as the following:
101
99
102
100
```cadence
103
101
let a = 1 > 2 ? 3 : 4
@@ -111,7 +109,7 @@ let a = 1 > 2 ? 3 : 4
111
109
112
110
The `=` (equals) symbol has several uses.
113
111
114
-
### Variable Declaration
112
+
### Variable declaration
115
113
116
114
```cadence
117
115
let a = 1 // declares a variable `a` with value `1`
@@ -125,9 +123,9 @@ a = 1 // assigns the value `1` to variable `a `
125
123
126
124
## `!` (exclamation mark)
127
125
128
-
The `!` (exclamation mark) symbol has a different effect whether it precedes or succeeds a variable.
126
+
The `!` (exclamation mark) symbol has a different effect depending on whether it precedes or succeeds a variable.
129
127
130
-
When it immediately **precedes** a boolean-type variable, it negates it.
128
+
When it immediately **precedes** a boolean-type variable, it negates it:
131
129
132
130
```cadence
133
131
let a: Bool = true
@@ -136,9 +134,7 @@ let b: Bool = !a
136
134
// b is false
137
135
```
138
136
139
-
When it immediately **succeeds** an *optional* variable, it [force-unwraps](./operators/optional-operators.md#force-unwrap-operator-) it.
140
-
Force-unwrapping returns the value inside an optional if it contains a value,
141
-
or panics and aborts the execution if the optional has no value, i.e. the optional value is nil.
137
+
When it immediately **succeeds** an _optional_ variable, it [force unwraps] it. Force unwrapping returns the value inside an optional if it contains a value, or panics and aborts the execution if the optional has no value (i.e., the optional value is nil):
142
138
143
139
```cadence
144
140
let a: Int? = nil
@@ -152,17 +148,17 @@ let d: Int = b! // initialized correctly as 3
152
148
153
149
The `/` (forward slash) symbol has several uses.
154
150
155
-
### Division Operator
151
+
### Division operator
156
152
157
-
Inbetween two expressions, the forward slash acts as the [division operator](./operators/arithmetic-logical-operators.md#arithmetic-operators).
153
+
Between two expressions, the forward slash acts as the [division operator]:
158
154
159
155
```cadence
160
156
let result = 4 / 2
161
157
```
162
158
163
159
### Path separator
164
160
165
-
In a [path](./accounts/paths.mdx), the forward slash separates the domain, `storage` or `public`, and the identifier.
161
+
In a [path], the forward slash separates the domain, `storage` or `public`, and the identifier:
166
162
167
163
```cadence
168
164
let storagePath = /storage/path
@@ -171,14 +167,12 @@ storagePath.toString() // is "/storage/path"
171
167
172
168
## `<-` (lower than, hyphen) (Move operator)
173
169
174
-
The [move operator `<-`](./resources.mdx#the-move-operator--) is like the assignment operator `=`,
175
-
but must be used when the value is a [resource](./resources.mdx).
176
-
To make assignment of resources explicit, the move operator `<-` must be used when:
170
+
The [move operator `<-`] is like the assignment operator `=`, but must be used when the value is a [resource]. To make the assignment of resources explicit, the move operator `<-` must be used when the resource is:
177
171
178
-
-The resource is the initial value of a constant or variable,
179
-
-The resource is moved to a different variable in an assignment,
180
-
-The resource is moved to a function as an argument
181
-
-The resource is returned from a function.
172
+
- the initial value of a constant or variable,
173
+
- moved to a different variable in an assignment,
174
+
- moved to a function as an argument, or
175
+
- returned from a function.
182
176
183
177
```cadence
184
178
resource R {}
@@ -188,9 +182,7 @@ let a <- create R() // we instantiate a new resource and move it into a
The [force-assignment move operator `<-!`](./operators/assign-move-force-swap.md#force-assignment-operator--) moves a resource value to an optional variable.
192
-
If the variable is `nil`, the move succeeds.
193
-
If it is not nil, the program aborts.
185
+
The [force-assignment move operator `<-!`] moves a resource value to an optional variable. If the variable is `nil`, the move succeeds. If it is not nil, the program aborts.
The [swapping operator `<->`](./operators/assign-move-force-swap.md#swapping-operator--) swaps two resource between the variables to the left and right of it.
206
-
197
+
The [swapping operator `<->`] swaps two resources between the variables to the left and right of it.
These are all typical [arithmetic operators](./operators/arithmetic-logical-operators.md#arithmetic-operators):
201
+
These are all typical [arithmetic operators]:
211
202
212
203
- Addition: `+`
213
204
- Subtraction: `-`
@@ -220,19 +211,17 @@ The `?` (question mark) symbol has several uses.
220
211
221
212
### Optional
222
213
223
-
If a `?` (question mark) follows a variable/constant, it represents an optional.
224
-
An optional can either have a value or *nothing at all*.
214
+
If a `?` (question mark) follows a variable/constant, it represents an optional. An optional can either have a value or _nothing at all_:
225
215
226
216
```cadence
227
217
// Declare a constant which has an optional integer type
228
218
//
229
219
let a: Int? = nil
230
220
```
231
221
232
-
### Ternary Conditional Operator
222
+
### Ternary conditional operator
233
223
234
-
The `?` (question mark) is also be used in [ternary operations](./operators/bitwise-ternary-operators.md#ternary-conditional-operator) to represent the "then" section,
235
-
such as the following:
224
+
The `?` (question mark) can also be used in [ternary operations] to represent the _then_ section, such as the following:
236
225
237
226
```cadence
238
227
let a = 1 > 2 ? 3 : 4
@@ -242,12 +231,11 @@ let a = 1 > 2 ? 3 : 4
242
231
// "otherwise, set a = 4.
243
232
```
244
233
245
-
### Nil-Coalescing Operator
234
+
### Nil-coalescing operator
246
235
247
-
The `?` (question mark) is also used in the [nil-coalescing operator `??`](./operators/optional-operators.md#nil-coalescing-operator-).
236
+
The `?` (question mark) is also used in the [nil-coalescing operator `??`].
248
237
249
-
It returns the value inside the optional, if the optional contains a value,
250
-
or returns an alternative value if the optional has no value, i.e., the optional value is nil.
238
+
It returns the value inside the optional if the optional contains a value, or returns an alternative value if the optional has no value (i.e., the optional value is nil):
251
239
252
240
```cadence
253
241
// Declare a constant which has an optional integer type
@@ -273,24 +261,24 @@ The `_` (underscore) symbol has several uses.
273
261
274
262
### Names
275
263
276
-
The `_` (underscore) can be used in names, e.g. in variables and types.
264
+
The `_` (underscore) can be used in names (e.g., in variables and types):
277
265
278
266
```cadence
279
267
let _a = true // used as a variable name
280
268
let another_one = false
281
269
```
282
270
283
-
### Number Literals
271
+
### Number literals
284
272
285
-
The `_` (underscore) can also be used to split up numerical components.
273
+
The `_` (underscore) can also be used to split up numerical components:
286
274
287
275
```cadence
288
276
let b = 100_000_000 // used to split up a number (supports all number types, e.g. 0b10_11_01)
289
277
```
290
278
291
-
### Argument Labels
279
+
### Argument labels
292
280
293
-
The `_` (underscore) can also be to indicate that a parameter in a [function](./functions.mdx) has no argument label.
281
+
The `_` (underscore) can also be used to indicate that a parameter in a [function] has no argument label:
294
282
295
283
```cadence
296
284
// The special argument label _ is specified for the parameter,
0 commit comments