Skip to content

Commit 0bf8c4e

Browse files
committed
Edit Glossary article
1 parent 51fe421 commit 0bf8c4e

1 file changed

Lines changed: 57 additions & 53 deletions

File tree

docs/language/glossary.mdx

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ title: Glossary
33
sidebar_position: 26
44
---
55

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

710
:::tip
811

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

1114
:::
1215

@@ -16,27 +19,25 @@ The `&` (ampersand) symbol has several uses.
1619

1720
### Reference
1821

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].
2023

2124
```cadence
2225
let a: String = "hello"
2326
let refOfA: &String = &a as &String
2427
```
2528

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

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).
3032

3133
```cadence
3234
let a: String = "hello"
3335
let refOfA: auth(X) &String = &a as auth(X) &String
3436
```
3537

36-
### Logical Operator
38+
### Logical operator
3739

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., `&&`):
4041

4142
```cadence
4243
let a = true
@@ -47,11 +48,9 @@ let c = a && b // false
4748

4849
## `@` (at)
4950

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].
5152

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

5655
```cadence
5756
// Declare a resource named `SomeResource`
@@ -69,7 +68,7 @@ resource SomeResource {
6968
// we use the '@' symbol to reference a resource type
7069
let a: @SomeResource <- create SomeResource(value: 0)
7170
72-
// also in functions declarations
71+
// also in function declarations
7372
access(all)
7473
fun use(resource: @SomeResource) {
7574
destroy resource
@@ -80,7 +79,7 @@ fun use(resource: @SomeResource) {
8079

8180
The `:` (colon) symbol has several uses.
8281

83-
### Type Declaration
82+
### Type declaration
8483

8584
If a `:` (colon) follows a variable/constant/function declaration, it is used to declare its type.
8685

@@ -94,10 +93,9 @@ fun addOne(x: Int): Int { // return type of Int
9493
}
9594
```
9695

97-
### Ternary Conditional Operator
96+
### Ternary conditional operator
9897

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:
10199

102100
```cadence
103101
let a = 1 > 2 ? 3 : 4
@@ -111,7 +109,7 @@ let a = 1 > 2 ? 3 : 4
111109

112110
The `=` (equals) symbol has several uses.
113111

114-
### Variable Declaration
112+
### Variable declaration
115113

116114
```cadence
117115
let a = 1 // declares a variable `a` with value `1`
@@ -125,9 +123,9 @@ a = 1 // assigns the value `1` to variable `a `
125123

126124
## `!` (exclamation mark)
127125

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

130-
When it immediately **precedes** a boolean-type variable, it negates it.
128+
When it immediately **precedes** a boolean-type variable, it negates it:
131129

132130
```cadence
133131
let a: Bool = true
@@ -136,9 +134,7 @@ let b: Bool = !a
136134
// b is false
137135
```
138136

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):
142138

143139
```cadence
144140
let a: Int? = nil
@@ -152,17 +148,17 @@ let d: Int = b! // initialized correctly as 3
152148

153149
The `/` (forward slash) symbol has several uses.
154150

155-
### Division Operator
151+
### Division operator
156152

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]:
158154

159155
```cadence
160156
let result = 4 / 2
161157
```
162158

163159
### Path separator
164160

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:
166162

167163
```cadence
168164
let storagePath = /storage/path
@@ -171,14 +167,12 @@ storagePath.toString() // is "/storage/path"
171167

172168
## `<-` (lower than, hyphen) (Move operator)
173169

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:
177171

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

183177
```cadence
184178
resource R {}
@@ -188,9 +182,7 @@ let a <- create R() // we instantiate a new resource and move it into a
188182

189183
## `<-!` (lower than, hyphen, exclamation mark) (Force-assignment move operator)
190184

191-
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.
194186

195187
```cadence
196188
access(all)
@@ -202,12 +194,11 @@ a <-! create R()
202194

203195
## `<->` (lower than, hyphen, greater than) (Swap operator)
204196

205-
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.
207198

208199
## `+` (plus), `-` (minus), `*` (asterisk), `%` (percentage sign)
209200

210-
These are all typical [arithmetic operators](./operators/arithmetic-logical-operators.md#arithmetic-operators):
201+
These are all typical [arithmetic operators]:
211202

212203
- Addition: `+`
213204
- Subtraction: `-`
@@ -220,19 +211,17 @@ The `?` (question mark) symbol has several uses.
220211

221212
### Optional
222213

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_:
225215

226216
```cadence
227217
// Declare a constant which has an optional integer type
228218
//
229219
let a: Int? = nil
230220
```
231221

232-
### Ternary Conditional Operator
222+
### Ternary conditional operator
233223

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:
236225

237226
```cadence
238227
let a = 1 > 2 ? 3 : 4
@@ -242,12 +231,11 @@ let a = 1 > 2 ? 3 : 4
242231
// "otherwise, set a = 4.
243232
```
244233

245-
### Nil-Coalescing Operator
234+
### Nil-coalescing operator
246235

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 `??`].
248237

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):
251239

252240
```cadence
253241
// Declare a constant which has an optional integer type
@@ -273,24 +261,24 @@ The `_` (underscore) symbol has several uses.
273261

274262
### Names
275263

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):
277265

278266
```cadence
279267
let _a = true // used as a variable name
280268
let another_one = false
281269
```
282270

283-
### Number Literals
271+
### Number literals
284272

285-
The `_` (underscore) can also be used to split up numerical components.
273+
The `_` (underscore) can also be used to split up numerical components:
286274

287275
```cadence
288276
let b = 100_000_000 // used to split up a number (supports all number types, e.g. 0b10_11_01)
289277
```
290278

291-
### Argument Labels
279+
### Argument labels
292280

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:
294282

295283
```cadence
296284
// The special argument label _ is specified for the parameter,
@@ -302,3 +290,19 @@ fun double(_ x: Int): Int {
302290
303291
let result = double(4)
304292
```
293+
294+
<!-- Relative links. Will not render on the page -->
295+
296+
[arithmetic operators]: ./operators/arithmetic-logical-operators.md#arithmetic-operators
297+
[division operator]: ./operators/arithmetic-logical-operators.md#arithmetic-operators
298+
[force-assignment move operator `<-!`]: ./operators/assign-move-force-swap.md#force-assignment-operator--
299+
[force unwraps]: ./operators/optional-operators.md#force-unwrap-operator-
300+
[function]: ./functions.mdx
301+
[logical operator (AND)]: ./operators/arithmetic-logical-operators.md#logical-operators
302+
[move operator `<-`]: ./resources.mdx#the-move-operator--
303+
[nil-coalescing operator `??`]: ./operators/optional-operators.md#nil-coalescing-operator-
304+
[path]: ./accounts/paths.mdx
305+
[reference]: ./references.mdx
306+
[resource]: ./resources.mdx
307+
[swapping operator `<->`]: ./operators/assign-move-force-swap.md#swapping-operator--
308+
[ternary operations]: ./operators/bitwise-ternary-operators.md#ternary-conditional-operator

0 commit comments

Comments
 (0)