Improve ReasonLIGO documentation a bit more.
This commit is contained in:
parent
814785644c
commit
1cbf828bdb
@ -54,7 +54,7 @@ let c: bool = (a = b)
|
||||
```reasonligo
|
||||
let a: string = "Alice";
|
||||
let b: string = "Alice";
|
||||
// true
|
||||
/* true */
|
||||
let c: bool = (a == b);
|
||||
```
|
||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||
@ -122,7 +122,7 @@ let c: bool = (a = b)
|
||||
```reasonligo
|
||||
let a: tez = 5mutez;
|
||||
let b: tez = 10mutez;
|
||||
// false
|
||||
/* false */
|
||||
let c: bool = (a == b);
|
||||
```
|
||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||
|
@ -80,7 +80,7 @@ along with a return type.
|
||||
Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
|
||||
|
||||
```reasonligo
|
||||
let add (a: int, b: int) : int = a + b;
|
||||
let add = (a: int, b: int) : int => a + b;
|
||||
```
|
||||
|
||||
The function body is a series of expressions, which are evaluated to give the return
|
||||
|
@ -63,18 +63,18 @@ let g: int = 1_000_000
|
||||
<!--ReasonLIGO-->
|
||||
|
||||
```reasonligo
|
||||
// int + int produces int
|
||||
/* int + int produces int */
|
||||
let a: int = 5 + 10;
|
||||
// nat + int produces int
|
||||
/* nat + int produces int */
|
||||
let b: int = 5n + 10;
|
||||
// tez + tez produces tez
|
||||
/* tez + tez produces tez */
|
||||
let c: tez = 5mutez + 10mutez;
|
||||
// you can't add tez + int or tez + nat, this won't compile
|
||||
// let d: tez = 5mutez + 10n;
|
||||
// two nats produce a nat
|
||||
/* you can't add tez + int or tez + nat, this won't compile */
|
||||
/* let d: tez = 5mutez + 10n; */
|
||||
/* two nats produce a nat */
|
||||
let e: nat = 5n + 10n;
|
||||
// nat + int produces an int, this won't compile
|
||||
// let f: nat = 5n + 10;
|
||||
/* nat + int produces an int, this won't compile */
|
||||
/* let f: nat = 5n + 10; */
|
||||
let g: int = 1_000_000;
|
||||
```
|
||||
|
||||
@ -116,10 +116,10 @@ let d: tez = 5mutez - 1mt
|
||||
<!--ReasonLIGO-->
|
||||
```reasonligo
|
||||
let a: int = 5 - 10;
|
||||
// substraction of two nats, yields an int
|
||||
/* substraction of two nats, yields an int */
|
||||
let b: int = 5n - 2n;
|
||||
// won't compile, result is an int, not a nat
|
||||
// let c: nat = 5n - 2n;
|
||||
/* won't compile, result is an int, not a nat */
|
||||
/* let c: nat = 5n - 2n; */
|
||||
let d: tez = 5mutez - 1mt;
|
||||
```
|
||||
|
||||
@ -152,7 +152,7 @@ let c: tez = 5n * 5mutez
|
||||
```reasonligo
|
||||
let a: int = 5 * 5;
|
||||
let b: nat = 5n * 5n;
|
||||
// you can also multiply `nat` and `tez`
|
||||
/* you can also multiply `nat` and `tez` */
|
||||
let c: tez = 5n * 5mutez;
|
||||
```
|
||||
|
||||
|
@ -258,7 +258,7 @@ let sum_of_a_list: int = List.fold sum my_list 0
|
||||
|
||||
```reasonligo
|
||||
let sum = (result: int, i: int): int => result + i;
|
||||
// Outputs 6
|
||||
/* Outputs 6 */
|
||||
let sum_of_a_list: int = List.fold(sum, my_list, 0);
|
||||
```
|
||||
|
||||
|
@ -17,7 +17,7 @@ const a: string = "Hello Alice";
|
||||
let a: string = "Hello Alice"
|
||||
```
|
||||
<!--ReasonLIGO-->
|
||||
```
|
||||
```reasonligo
|
||||
let a: string = "Hello Alice";
|
||||
```
|
||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||
|
@ -57,9 +57,9 @@ let ledger: account_balances = Map.literal
|
||||
[(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), 10mutez)]
|
||||
```
|
||||
|
||||
<!--Reasonligo-->
|
||||
<!--ReasonLIGO-->
|
||||
```reasonligo
|
||||
// account_balances is a simple type, a map of address <-> tez
|
||||
/* account_balances is a simple type, a map of address <-> tez */
|
||||
type account_balances = map(address, tez);
|
||||
|
||||
let ledger: account_balances =
|
||||
@ -122,7 +122,7 @@ let ledger: account_balances = Map.literal
|
||||
)]
|
||||
```
|
||||
|
||||
<!--Reasonligo-->
|
||||
<!--ReasonLIGO-->
|
||||
```reasonligo
|
||||
/* alias two types */
|
||||
type account = address;
|
||||
@ -135,8 +135,8 @@ type account_data = {
|
||||
/* our ledger / account_balances is a map of account <-> account_data */
|
||||
type account_balances = map(account, account_data);
|
||||
|
||||
// pseudo-JSON representation of our map
|
||||
// {"tz1...": {balance: 10mutez, number_of_transactions: 5n}}
|
||||
/* pseudo-JSON representation of our map */
|
||||
/* {"tz1...": {balance: 10mutez, number_of_transactions: 5n}} */
|
||||
let ledger: account_balances =
|
||||
Map.literal([
|
||||
(
|
||||
|
@ -5,8 +5,6 @@ title: Constants & Variables
|
||||
|
||||
The next building block after types are constants and variables.
|
||||
|
||||
pleh.
|
||||
|
||||
## Constants
|
||||
|
||||
Constants are immutable by design, which means their values can't be reassigned.
|
||||
|
Loading…
Reference in New Issue
Block a user