Skip to content

Commit 0645c73

Browse files
authored
Merge pull request #429 from quyenducngo/patch-10
Update language copy and typos
2 parents 3471b83 + f582664 commit 0645c73

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

documentation/aleo/03_language.md

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ sidebar_label: Language
66

77
### Statically Typed
88

9-
Aleo instructions is a **statically typed language**, which means we must know the type of each variable before executing a circuit.
9+
Aleo instructions is a **statically typed language**, which means we must know the type of each register for the code to be valid.
1010

1111
### Explicit Types Required
1212

13-
There is no `undefined` or `null` value in Aleo instructions. When assigning a new variable, **the type of the value must be explicitly stated**.
13+
There is no `undefined` or `null` value in Aleo instructions. Every register must have an e**xplicitly stated** or **statically inferred**.
1414

1515
### Pass by Value
1616

17-
Expressions in Aleo instructions are always **passed by value**, which means their values are always copied when they are used as function inputs or in right sides of assignments.
17+
Arguments in Aleo instructions are always **passed by value**, which means their values are always copied when they are used as function inputs or in right sides of assignments.
1818

1919
### Register based
2020

2121
There are no variable names in Aleo instructions.
22-
All variables are stored in registers denoted `rX` where `X` is a non-negative whole number starting from 0 `r0, r1, r2, etc.`.
22+
All values are stored in registers denoted `rX` where `X` is a non-negative whole number starting from 0 `r0, r1, r2, etc.`.
2323

2424
## Data Types and Values
2525

2626
### Booleans
2727

28-
Aleo instructions supports the traditional `true` or `false` boolean values. The explicit `boolean` type for booleans in statements is required.
28+
Aleo instructions supports the traditional `true` or `false` boolean values. The explicit `boolean` type for booleans in instructions is required.
2929

3030
```aleo
3131
function main:
@@ -59,9 +59,9 @@ function main:
5959

6060
### Group Elements
6161

62-
The set of affine points on the elliptic curve passed into the Aleo instructions compiler forms a group.
62+
The set of affine points on the elliptic curve that Aleo instructions are based on forms a group.
6363
The curve is a Twisted Edwards curve with `a = -1` and `d = 3021`.
64-
Aleo instructions supports a subgroup of the group, generated by a generator point, as a primitive data type.
64+
Aleo instructions support a subgroup of the group, generated by a generator point, as a primitive data type.
6565
A group element is denoted by the x-coordinate of its point; for example,
6666
`2group` means the point `(2, 5553594316923449299484601589326170487897520766531075014687114064346375156608)`.
6767
The generator point is `1540945439182663264862696551825005342995406165131907382295858612069623286213group`.
@@ -103,15 +103,14 @@ sign.verify sign069ju4e8s66unu25celqycvsv3k9chdyz4n4sy62tx6wxj0u25vqp58hgu9hwyqc
103103
## Layout of an Aleo Program
104104

105105
An Aleo program contains declarations of a [Program ID](#programid), [Imports](#import), [Functions](#function), [Closures](#closure), [Structs](#struct), [Records](#record),
106-
[Mappings](#mapping), and [Finalize](#finalize). Ordering is only enforced for imports which must be at the top of file.
106+
[Mappings](#mapping), and [Finalizers](#finalize). Ordering is only enforced for imports which must be at the top of the file.
107107
Declarations are locally accessible within a program file.
108108
If you need a declaration from another program file, you must import it.
109109

110110
### Program ID
111111

112112
A program ID is declared as `{name}.{network}`.
113-
The first character of a `name` must be lowercase.
114-
`name` can contain lowercase letters, numbers, and underscores.
113+
`name` must start with a lowercase letter and only contain lowercase letters, digits, and underscores.
115114
Currently, `aleo` is the only supported `network` domain.
116115

117116
```aleo showLineNumbers
@@ -153,7 +152,7 @@ function foo:
153152
#### Function Inputs
154153

155154
A function input is declared as `input {register} as {type}.{visibility};`.
156-
Function inputs must be declared just after the function name declaration.
155+
Function inputs must be declared just after the function name declaration and before instructions.
157156

158157
```aleo showLineNumbers
159158
// The function `foo` takes a single input `r0` with type `field` and visibility `public`.
@@ -175,8 +174,8 @@ Function outputs must be declared at the end of the function definition.
175174

176175
In the Aleo protocol, calling a function creates a transition that can consume and produce records on-chain.
177176
Use the `aleo run` CLI command to pass inputs to a function and execute the program.
178-
In Testnet3, program functions cannot call other internal program functions.
179-
If you would like to develop "helper functions" that are called internally within a program, try writing a `closure`.
177+
In Testnet, program functions cannot call other internal program functions.
178+
If you would like to develop "helper functions" that are called internally within a program, write a `closure`.
180179

181180
#### Call an Imported Function
182181

@@ -189,15 +188,22 @@ program bar.aleo;
189188
190189
function call_external:
191190
input r0 as u64.private;
192-
call foo.aleo/baz r0 into r1; // Externally call function `baz` in foo.aleo with argument `r0` and store the result in `r1`.
193-
output r1;
191+
input r1 as u64.private;
192+
193+
// Externally call function `baz` in foo.aleo with arguments `r0` and `r1`,
194+
// and store the results in `r2` and `r3`.
195+
call foo.aleo/baz r0 r1 into r2 r3;
196+
197+
output r2;
198+
output r3;
194199
```
195200

196201
### Closure
197202

198203
A closure is declared as `closure {name}:`.
199204
Closures contain instructions that can compute values.
200-
Closures are helper functions that cannot be executed directly. Closures may be called by other functions.
205+
Closures are helper functions that cannot be executed directly from the CLI to create transitions.
206+
Closures may be called by other functions.
201207

202208
```aleo showLineNumbers
203209
closure foo:
@@ -216,8 +222,14 @@ program bar.aleo;
216222
217223
function call_internal:
218224
input r0 as u64.private;
219-
call foo r0 into r1; // Internally call closure `foo` with argument `r0` and store the result in `r1`.
220-
output r1;
225+
input r1 as u64.private;
226+
227+
// Internally call closure `foo` with arguments `r0` and `r1`,
228+
// and store the results in `r2` and `r3`.
229+
call foo r0 r1 into r2 r3;
230+
231+
output r2;
232+
output r3;
221233
```
222234

223235
### Struct
@@ -245,7 +257,7 @@ function new_array3:
245257

246258
### Array
247259

248-
An array is a data type declared as `[{value}, {value}]`.
260+
An array is an aggregate value denoated as `[{value}, ..., {value}]`.
249261

250262
```aleo
251263
[true, false, true]
@@ -340,7 +352,7 @@ mapping account:
340352

341353
#### Contains
342354

343-
A contains command that checks if a key exists in a mapping, e.g. `contains accounts[r0] into r1;`.
355+
A contains command checks if a key exists in a mapping and stores the boolean result in the into register. For example: `contains accounts[r0] into r1;`.
344356

345357
#### Get
346358

@@ -460,7 +472,7 @@ For example, `await r0;`.
460472
An `await` command can only be used in a finalize block.
461473
The operand must be a register containing a Future.
462474

463-
#### Indexing a future.
475+
#### Indexing a future
464476
A register containing a future can be indexed using the existing index syntax.
465477
For example, `r0[0u32]`.
466478
This would get the input of the future at that specific index.
@@ -530,8 +542,8 @@ finalize add_and_subtract:
530542
There are a number of rules associated with using these components.
531543

532544
1. If a function has a finalize block, it must have exactly one async instruction.
533-
2. If a function has a finalize block, it's last output must be a future.
534-
3. If a function does not have a finalize block, it cannot have an async instruction`.
545+
2. If a function has a finalize block, its last output must be a future.
546+
3. If a function does not have a finalize block, it cannot have an async instruction.
535547
4. All futures created by calls need to be input to the async instruction in the order they were produced.
536548
5. An async call must reference the same function.
537549
6. All calls must be made before invoking async.
@@ -620,8 +632,8 @@ Checkout the [Aleo Instructions opcodes](./04_opcodes.md) for a full list of sup
620632
#### position, branch.eq, branch.neq
621633

622634
The `position` command, e.g. `position exit`, indicates a point to branch execution to.
623-
The `branch.eq` command, e.g. `branch.eq r0 r1 to exit`, which branches execution to the position indicated by `exit` if `r0` and `r1` are equal.
624-
The `branch.neq` command, e.g. `branch.neq r0 r1 to exit`, which branches execution to the position indicated by `exit` if `r0` and `r1` are not equal.
635+
The `branch.eq` command, e.g. `branch.eq r0 r1 to exit`, branches execution to the position indicated by `exit` if `r0` and `r1` are equal.
636+
The `branch.neq` command, e.g. `branch.neq r0 r1 to exit`, branches execution to the position indicated by `exit` if `r0` and `r1` are not equal.
625637

626638
** Example **
627639
The finalize block exits successfully if the input is 0u8 and fails otherwise.
@@ -713,7 +725,7 @@ $ snarkvm execute foo
713725

714726
#### User Callable Program
715727

716-
By `asserting assert.eq self.caller self.signer;` on line 4, a developer can restrict their function such that it can only be called by users.
728+
By asserting `assert.eq self.caller self.signer;` on line 4, a developer can restrict their function such that it can only be called by users.
717729
```aleo showLineNumbers title="./imports/child.aleo"
718730
program child.aleo;
719731

0 commit comments

Comments
 (0)