Merge branch 'fix_docs_reasonligo' into 'dev'
Improve ReasonLIGO documentation. See merge request ligolang/ligo!244
This commit is contained in:
commit
814785644c
@ -21,7 +21,7 @@ let a: bool = true
|
|||||||
let b: bool = false
|
let b: bool = false
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: bool = true;
|
let a: bool = true;
|
||||||
let b: bool = false;
|
let b: bool = false;
|
||||||
@ -50,7 +50,7 @@ let b: string = "Alice"
|
|||||||
// true
|
// true
|
||||||
let c: bool = (a = b)
|
let c: bool = (a = b)
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: string = "Alice";
|
let a: string = "Alice";
|
||||||
let b: string = "Alice";
|
let b: string = "Alice";
|
||||||
@ -86,7 +86,7 @@ let g: bool = (a >= b)
|
|||||||
let h: bool = (a =/= b)
|
let h: bool = (a =/= b)
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: int = 5;
|
let a: int = 5;
|
||||||
let b: int = 4;
|
let b: int = 4;
|
||||||
@ -118,7 +118,7 @@ let b: tez = 10mutez
|
|||||||
// false
|
// false
|
||||||
let c: bool = (a = b)
|
let c: bool = (a = b)
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: tez = 5mutez;
|
let a: tez = 5mutez;
|
||||||
let b: tez = 10mutez;
|
let b: tez = 10mutez;
|
||||||
@ -176,7 +176,7 @@ let min_age: nat = 16n
|
|||||||
let is_adult (age: nat) : bool =
|
let is_adult (age: nat) : bool =
|
||||||
if (age > min_age) then true else false
|
if (age > min_age) then true else false
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let min_age: nat = 16n;
|
let min_age: nat = 16n;
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ let is_adult = (age: nat): bool =>
|
|||||||
|
|
||||||
> You can run the function above with
|
> You can run the function above with
|
||||||
> ```
|
> ```
|
||||||
> ligo run-function -s cameligo src/if-else.mligo is_adult 21n
|
> ligo run-function -s reasonligo src/if-else.religo is_adult 21n
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
@ -70,6 +70,22 @@ let add (a: int) (b: int) : int = a + b
|
|||||||
The function body is a series of expressions, which are evaluated to give the return
|
The function body is a series of expressions, which are evaluated to give the return
|
||||||
value.
|
value.
|
||||||
|
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
|
Functions in ReasonLIGO are defined using the `let` keyword, like value bindings.
|
||||||
|
The difference is that after the value name a list of function parameters is provided,
|
||||||
|
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;
|
||||||
|
```
|
||||||
|
|
||||||
|
The function body is a series of expressions, which are evaluated to give the return
|
||||||
|
value.
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
@ -99,7 +115,7 @@ const a: int = increment(1);
|
|||||||
let increment : (int -> int) = fun (i: int) -> i + 1
|
let increment : (int -> int) = fun (i: int) -> i + 1
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let increment: (int => int) = (i: int) => i + 1;
|
let increment: (int => int) = (i: int) => i + 1;
|
||||||
```
|
```
|
||||||
|
@ -22,7 +22,7 @@ type ledger is map(address, tez);
|
|||||||
type ledger = (address, tez) map
|
type ledger = (address, tez) map
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type ledger = map(address, tez);
|
type ledger = map(address, tez);
|
||||||
```
|
```
|
||||||
@ -57,19 +57,19 @@ let ledger: ledger = Map.literal
|
|||||||
>
|
>
|
||||||
> `("<string value>": address)` means that we type-cast a string into an address.
|
> `("<string value>": address)` means that we type-cast a string into an address.
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let ledger: ledger =
|
let ledger: ledger =
|
||||||
Map.literal([
|
Map.literal([
|
||||||
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, 1000(mutez)),
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, 1000mutez),
|
||||||
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, 2000(mutez)),
|
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address, 2000mutez),
|
||||||
]);
|
]);
|
||||||
|
```
|
||||||
> Map.literal constructs the map from a list of key-value pair tuples, `(<key>, <value>)`.
|
> Map.literal constructs the map from a list of key-value pair tuples, `(<key>, <value>)`.
|
||||||
>
|
>
|
||||||
> `("<string value>": address)` means that we type-cast a string into an address.
|
> `("<string value>": address)` means that we type-cast a string into an address.
|
||||||
```
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
### Accessing map values by key
|
### Accessing map values by key
|
||||||
@ -88,7 +88,7 @@ const balance: option(tez) = ledger[("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": add
|
|||||||
let balance: tez option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) ledger
|
let balance: tez option = Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) ledger
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let balance: option(tez) =
|
let balance: option(tez) =
|
||||||
@ -112,7 +112,7 @@ const balance: tez = get_force(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)
|
|||||||
let balance: tez = Map.find ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) ledger
|
let balance: tez = Map.find ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) ledger
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let balance: tez =
|
let balance: tez =
|
||||||
@ -146,7 +146,7 @@ let iter_op (m : ledger) : unit =
|
|||||||
in Map.iter assert_eq m
|
in Map.iter assert_eq m
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let iter_op = (m: ledger): unit => {
|
let iter_op = (m: ledger): unit => {
|
||||||
let assert_eq = (i: address, j: tez) => assert(j > 100);
|
let assert_eq = (i: address, j: tez) => assert(j > 100);
|
||||||
@ -173,7 +173,7 @@ let map_op (m : ledger) : ledger =
|
|||||||
in Map.map increment m
|
in Map.map increment m
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let map_op = (m: ledger): ledger => {
|
let map_op = (m: ledger): ledger => {
|
||||||
let increment = (ignore: address, j: tez) => j + 1;
|
let increment = (ignore: address, j: tez) => j + 1;
|
||||||
@ -207,7 +207,7 @@ let fold_op (m : ledger) : ledger =
|
|||||||
in Map.fold aggregate m 10
|
in Map.fold aggregate m 10
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let fold_op = (m: ledger): ledger => {
|
let fold_op = (m: ledger): ledger => {
|
||||||
let aggregate = (ignore: address, j: (tez, tez)) => j[0] + j[1];
|
let aggregate = (ignore: address, j: (tez, tez)) => j[0] + j[1];
|
||||||
@ -243,7 +243,7 @@ type user = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type user = {
|
type user = {
|
||||||
id: nat,
|
id: nat,
|
||||||
@ -275,7 +275,7 @@ let user: user = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let user: user = {
|
let user: user = {
|
||||||
id: 1n,
|
id: 1n,
|
||||||
@ -301,7 +301,7 @@ const is_admin: bool = user.is_admin;
|
|||||||
let is_admin: bool = user.is_admin
|
let is_admin: bool = user.is_admin
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let is_admin: bool = user.is_admin;
|
let is_admin: bool = user.is_admin;
|
||||||
```
|
```
|
||||||
|
@ -60,7 +60,7 @@ let g: int = 1_000_000
|
|||||||
>let g: int = 1_000_000;
|
>let g: int = 1_000_000;
|
||||||
>```
|
>```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
// int + int produces int
|
// int + int produces int
|
||||||
@ -71,6 +71,7 @@ let b: int = 5n + 10;
|
|||||||
let c: tez = 5mutez + 10mutez;
|
let c: tez = 5mutez + 10mutez;
|
||||||
// you can't add tez + int or tez + nat, this won't compile
|
// you can't add tez + int or tez + nat, this won't compile
|
||||||
// let d: tez = 5mutez + 10n;
|
// let d: tez = 5mutez + 10n;
|
||||||
|
// two nats produce a nat
|
||||||
let e: nat = 5n + 10n;
|
let e: nat = 5n + 10n;
|
||||||
// nat + int produces an int, this won't compile
|
// nat + int produces an int, this won't compile
|
||||||
// let f: nat = 5n + 10;
|
// let f: nat = 5n + 10;
|
||||||
@ -112,7 +113,7 @@ let b: int = 5n - 2n
|
|||||||
let d: tez = 5mutez - 1mt
|
let d: tez = 5mutez - 1mt
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: int = 5 - 10;
|
let a: int = 5 - 10;
|
||||||
// substraction of two nats, yields an int
|
// substraction of two nats, yields an int
|
||||||
@ -147,7 +148,7 @@ let b: nat = 5n * 5n
|
|||||||
let c: tez = 5n * 5mutez
|
let c: tez = 5n * 5mutez
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: int = 5 * 5;
|
let a: int = 5 * 5;
|
||||||
let b: nat = 5n * 5n;
|
let b: nat = 5n * 5n;
|
||||||
@ -179,7 +180,7 @@ let b: nat = 10n / 3n
|
|||||||
let c: nat = 10mutez / 3mutez
|
let c: nat = 10mutez / 3mutez
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let a: int = 10 / 3;
|
let a: int = 10 / 3;
|
||||||
let b: nat = 10n / 3n;
|
let b: nat = 10n / 3n;
|
||||||
@ -199,4 +200,10 @@ const a: int = int(1n);
|
|||||||
const b: nat = abs(1);
|
const b: nat = abs(1);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```reasonligo
|
||||||
|
let a: int = int(1n);
|
||||||
|
let b: nat = abs(1);
|
||||||
|
```
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
@ -31,7 +31,7 @@ let my_set: int_set =
|
|||||||
Set.add 3 (Set.add 2 (Set.add 1 (Set.empty: int set)))
|
Set.add 3 (Set.add 2 (Set.add 1 (Set.empty: int set)))
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type int_set = set(int);
|
type int_set = set(int);
|
||||||
let my_set: int_set =
|
let my_set: int_set =
|
||||||
@ -52,7 +52,7 @@ const my_set_2: int_set = set_empty;
|
|||||||
```cameligo
|
```cameligo
|
||||||
let my_set: int_set = (Set.empty: int set)
|
let my_set: int_set = (Set.empty: int set)
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let my_set: int_set = (Set.empty: set(int));
|
let my_set: int_set = (Set.empty: set(int));
|
||||||
```
|
```
|
||||||
@ -72,7 +72,7 @@ const contains_three_fn: bool = set_mem(3, my_set);
|
|||||||
```cameligo
|
```cameligo
|
||||||
let contains_three: bool = Set.mem 3 my_set
|
let contains_three: bool = Set.mem 3 my_set
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let contains_three: bool = Set.mem(3, my_set);
|
let contains_three: bool = Set.mem(3, my_set);
|
||||||
```
|
```
|
||||||
@ -92,7 +92,7 @@ const set_size: nat = size(my_set);
|
|||||||
let set_size: nat = Set.size my_set
|
let set_size: nat = Set.size my_set
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let set_size: nat = Set.size(my_set);
|
let set_size: nat = Set.size(my_set);
|
||||||
```
|
```
|
||||||
@ -115,7 +115,7 @@ let larger_set: int_set = Set.add 4 my_set
|
|||||||
let smaller_set: int_set = Set.remove 3 my_set
|
let smaller_set: int_set = Set.remove 3 my_set
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let larger_set: int_set = Set.add(4, my_set);
|
let larger_set: int_set = Set.add(4, my_set);
|
||||||
@ -140,7 +140,7 @@ let sum (result: int) (i: int) : int = result + i
|
|||||||
let sum_of_a_set: int = Set.fold sum my_set 0
|
let sum_of_a_set: int = Set.fold sum my_set 0
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let sum = (result: int, i: int): int => result + i;
|
let sum = (result: int, i: int): int => result + i;
|
||||||
let sum_of_a_set: int = Set.fold(sum, my_set, 0);
|
let sum_of_a_set: int = Set.fold(sum, my_set, 0);
|
||||||
@ -172,7 +172,7 @@ type int_list = int list
|
|||||||
let my_list: int_list = [1; 2; 3]
|
let my_list: int_list = [1; 2; 3]
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type int_list = list(int);
|
type int_list = list(int);
|
||||||
let my_list: int_list = [1, 2, 3];
|
let my_list: int_list = [1, 2, 3];
|
||||||
@ -196,10 +196,10 @@ let larger_list: int_list = 4 :: my_list
|
|||||||
(* CameLIGO doesn't have a List.cons *)
|
(* CameLIGO doesn't have a List.cons *)
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let larger_list: int_list = [4, ...my_list];
|
let larger_list: int_list = [4, ...my_list];
|
||||||
/* Reasonligo doesn't have a List.cons */
|
/* ReasonLIGO doesn't have a List.cons */
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
@ -226,7 +226,7 @@ let incremented_list: int_list = List.map increment larger_list
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let increment = (i: int): int => i + 1;
|
let increment = (i: int): int => i + 1;
|
||||||
@ -254,7 +254,7 @@ let sum (result: int) (i: int) : int = result + i
|
|||||||
let sum_of_a_list: int = List.fold sum my_list 0
|
let sum_of_a_list: int = List.fold sum my_list 0
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let sum = (result: int, i: int): int => result + i;
|
let sum = (result: int, i: int): int => result + i;
|
||||||
@ -299,7 +299,7 @@ type full_name = string * string
|
|||||||
let full_name: full_name = ("Alice", "Johnson")
|
let full_name: full_name = ("Alice", "Johnson")
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type full_name = (string, string);
|
type full_name = (string, string);
|
||||||
/* The parenthesis here are optional */
|
/* The parenthesis here are optional */
|
||||||
@ -329,7 +329,7 @@ const first_name: string = full_name.1;
|
|||||||
let first_name: string = full_name.1
|
let first_name: string = full_name.1
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let first_name: string = full_name[1];
|
let first_name: string = full_name[1];
|
||||||
```
|
```
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
let add = (a: int, b: int): int => {
|
||||||
|
let c: int = a + b;
|
||||||
|
c;
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
let age : int = 25;
|
@ -16,15 +16,19 @@ const a: string = "Hello Alice";
|
|||||||
```
|
```
|
||||||
let a: string = "Hello Alice"
|
let a: string = "Hello Alice"
|
||||||
```
|
```
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```
|
||||||
|
let a: string = "Hello Alice";
|
||||||
|
```
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
|
||||||
## Concatenating strings
|
## Concatenating strings
|
||||||
|
|
||||||
Strings can be concatenated using the `^` operator.
|
|
||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
|
Strings can be concatenated using the `^` operator.
|
||||||
|
|
||||||
```pascaligo
|
```pascaligo
|
||||||
const name: string = "Alice";
|
const name: string = "Alice";
|
||||||
const greeting: string = "Hello";
|
const greeting: string = "Hello";
|
||||||
@ -34,12 +38,16 @@ const full_greeting: string = greeting ^ " " ^ name;
|
|||||||
const full_greeting_exclamation: string = string_concat(full_greeting, "!");
|
const full_greeting_exclamation: string = string_concat(full_greeting, "!");
|
||||||
```
|
```
|
||||||
<!--Cameligo-->
|
<!--Cameligo-->
|
||||||
|
Strings can be concatenated using the `^` operator.
|
||||||
|
|
||||||
```cameligo
|
```cameligo
|
||||||
let name: string = "Alice"
|
let name: string = "Alice"
|
||||||
let greeting: string = "Hello"
|
let greeting: string = "Hello"
|
||||||
let full_greeting: string = greeting ^ " " ^ name
|
let full_greeting: string = greeting ^ " " ^ name
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
Strings can be concatenated using the `++` operator.
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let name: string = "Alice";
|
let name: string = "Alice";
|
||||||
let greeting: string = "Hello";
|
let greeting: string = "Hello";
|
||||||
@ -64,7 +72,7 @@ const slice: string = string_slice(0n, 1n, name);
|
|||||||
let name: string = "Alice"
|
let name: string = "Alice"
|
||||||
let slice: string = String.slice 0n 1n name
|
let slice: string = String.slice 0n 1n name
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let name: string = "Alice";
|
let name: string = "Alice";
|
||||||
let slice: string = String.slice(0n, 1n, name);
|
let slice: string = String.slice(0n, 1n, name);
|
||||||
@ -89,7 +97,7 @@ const length: nat = size(name);
|
|||||||
let name: string = "Alice"
|
let name: string = "Alice"
|
||||||
let length: nat = String.size name
|
let length: nat = String.size name
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let name: string = "Alice";
|
let name: string = "Alice";
|
||||||
let length: nat = String.size(name);
|
let length: nat = String.size(name);
|
||||||
|
@ -27,7 +27,7 @@ type animal_breed = string
|
|||||||
let dog_breed: animal_breed = "Saluki"
|
let dog_breed: animal_breed = "Saluki"
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type animal_breed = string;
|
type animal_breed = string;
|
||||||
@ -64,7 +64,7 @@ type account_balances = map(address, tez);
|
|||||||
|
|
||||||
let ledger: account_balances =
|
let ledger: account_balances =
|
||||||
Map.literal([
|
Map.literal([
|
||||||
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, 10(mutez)),
|
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address, 10mutez),
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ let ledger: account_balances =
|
|||||||
Map.literal([
|
Map.literal([
|
||||||
(
|
(
|
||||||
"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address,
|
"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address,
|
||||||
{balance: 10(mutez), number_of_transactions: 5n},
|
{balance: 10mutez, number_of_transactions: 5n},
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ const n: unit = Unit;
|
|||||||
let n: unit = ()
|
let n: unit = ()
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let n: unit = ();
|
let n: unit = ();
|
||||||
```
|
```
|
||||||
@ -62,7 +62,7 @@ let u: user = Admin 1000n
|
|||||||
let g: user = Guest ()
|
let g: user = Guest ()
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type id = nat;
|
type id = nat;
|
||||||
type user =
|
type user =
|
||||||
@ -101,7 +101,7 @@ let p1: dinner = None
|
|||||||
let p2: dinner = Some "Hamburgers"
|
let p2: dinner = Some "Hamburgers"
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type dinner = option(string);
|
type dinner = option(string);
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ let is_hungry (d: dinner) : bool =
|
|||||||
| Some s -> false
|
| Some s -> false
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
type dinner = option(string);
|
type dinner = option(string);
|
||||||
let is_hungry = (d: dinner): bool =>
|
let is_hungry = (d: dinner): bool =>
|
||||||
|
@ -5,6 +5,8 @@ title: Constants & Variables
|
|||||||
|
|
||||||
The next building block after types are constants and variables.
|
The next building block after types are constants and variables.
|
||||||
|
|
||||||
|
pleh.
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
|
|
||||||
Constants are immutable by design, which means their values can't be reassigned.
|
Constants are immutable by design, which means their values can't be reassigned.
|
||||||
@ -32,7 +34,7 @@ ligo evaluate-value -s cameligo gitlab-pages/docs/language-basics/src/variables-
|
|||||||
# Outputs: 25
|
# Outputs: 25
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo
|
||||||
let age: int = 25;
|
let age: int = 25;
|
||||||
```
|
```
|
||||||
@ -98,9 +100,9 @@ You can run the `add` function defined above using the LIGO compiler like this:
|
|||||||
ligo run-function -s cameligo gitlab-pages/docs/language-basics/src/variables-and-constants/add.mligo add '(1,1)'
|
ligo run-function -s cameligo gitlab-pages/docs/language-basics/src/variables-and-constants/add.mligo add '(1,1)'
|
||||||
# Outputs: 2
|
# Outputs: 2
|
||||||
```
|
```
|
||||||
<!--Reasonligo-->
|
<!--ReasonLIGO-->
|
||||||
|
|
||||||
As expected from a functional language, Reasonligo uses value-binding
|
As expected from a functional language, ReasonLIGO uses value-binding
|
||||||
for variables rather than assignment. Variables are changed by replacement,
|
for variables rather than assignment. Variables are changed by replacement,
|
||||||
with a new value being bound in place of the old one.
|
with a new value being bound in place of the old one.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user