diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md
index 6e5abbca0..429962a33 100644
--- a/gitlab-pages/docs/advanced/entrypoints-contracts.md
+++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md
@@ -194,8 +194,8 @@ how those built-ins can be utilized.
### Accepting or Declining Tokens in a Smart Contract
-This example shows how `amount` and `failwith` can be used to decline
-any transaction that sends more tez than `0mutez`, that is, no
+This example shows how `Tezos.amount` and `failwith` can be used to
+decline any transaction that sends more tez than `0tez`, that is, no
incoming tokens are accepted.
@@ -206,11 +206,13 @@ type storage is unit
type return is list (operation) * storage
function deny (const action : parameter; const store : storage) : return is
- if amount > 0mutez then
+ if Tezos.amount > 0tez then
(failwith ("This contract does not accept tokens.") : return)
else ((nil : list (operation)), store)
```
+> Note that `amount` is *deprecated*.
+
```cameligo group=c
type parameter = unit
@@ -218,11 +220,13 @@ type storage = unit
type return = operation list * storage
let deny (action, store : parameter * storage) : return =
- if amount > 0mutez then
- (failwith "This contract does not accept tokens.": return)
+ if Tezos.amount > 0tez then
+ (failwith "This contract does not accept tokens." : return)
else (([] : operation list), store)
```
+> Note that `amount` is *deprecated*.
+
```reasonligo group=c
type parameter = unit;
@@ -230,17 +234,20 @@ type storage = unit;
type return = (list (operation), storage);
let deny = ((action, store): (parameter, storage)) : return => {
- if (amount > 0mutez) {
+ if (Tezos.amount > 0tez) {
(failwith("This contract does not accept tokens."): return); }
else { (([] : list (operation)), store); };
};
```
+> Note that `amount` is *deprecated*.
+
### Access Control
-This example shows how `sender` or `source` can be used to deny access to an entrypoint.
+This example shows how `Tezos.source` can be used to deny access to an
+entrypoint.
@@ -248,28 +255,35 @@ This example shows how `sender` or `source` can be used to deny access to an ent
const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address);
function main (const action : parameter; const store : storage) : return is
- if source =/= owner then (failwith ("Access denied.") : return)
- else ((nil : list(operation)), store)
+ if Tezos.source =/= owner then (failwith ("Access denied.") : return)
+ else ((nil : list (operation)), store)
```
+> Note that `source` is *deprecated*.
+
```cameligo group=c
let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)
let main (action, store: parameter * storage) : return =
- if source <> owner then (failwith "Access denied." : return)
+ if Tezos.source <> owner then (failwith "Access denied." : return)
else (([] : operation list), store)
```
+> Note that `source` is *deprecated*.
+
```reasonligo group=c
let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address);
-let main = ((action, store): (parameter, storage)) : storage => {
- if (source != owner) { (failwith ("Access denied.") : return); }
+let main = ((action, store) : (parameter, storage)) : storage => {
+ if (Tezos.source != owner) { (failwith ("Access denied.") : return); }
else { (([] : list (operation)), store); };
};
```
+
+> Note that `source` is *deprecated*.
+
### Inter-Contract Invocations
@@ -327,11 +341,15 @@ const dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address)
function proxy (const action : parameter; const store : storage): return is
block {
- const counter : contract (parameter) = get_contract (dest);
+ const counter : contract (parameter) =
+ case (Tezos.get_contract_opt (dest) : option (contract (parameter))) of
+ Some (contract) -> contract
+ | None -> (failwith ("Contract not found.") : contract (parameter))
+ end;
(* Reuse the parameter in the subsequent
transaction or use another one, `mock_param`. *)
const mock_param : parameter = Increment (5n);
- const op : operation = transaction (action, 0mutez, counter);
+ const op : operation = Tezos.transaction (action, 0tez, counter);
const ops : list (operation) = list [op]
} with (ops, store)
```
@@ -363,14 +381,20 @@ type return = operation list * storage
let dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address)
let proxy (action, store : parameter * storage) : return =
- let counter : parameter contract = Operation.get_contract dest in
+ let counter : parameter contract =
+ match (Tezos.get_contract_opt (dest) : parameter contract option) with
+ Some contract -> contract
+ | None -> (failwith "Contract not found." : parameter contract) in
(* Reuse the parameter in the subsequent
transaction or use another one, `mock_param`. *)
let mock_param : parameter = Increment (5n) in
- let op : operation = Operation.transaction action 0mutez counter
+ let op : operation = Tezos.transaction action 0tez counter
in [op], store
```
+> Note that `Operation.get_contract` and `Operation.transaction` are
+> *deprecated*.
+
```reasonligo skip
// counter.religo
@@ -398,13 +422,20 @@ type return = (list (operation), storage);
let dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address);
let proxy = ((action, store): (parameter, storage)) : return => {
- let counter : contract (parameter) = Operation.get_contract (dest);
+ let counter : contract (parameter) =
+ switch (Tezos.get_contract_opt (dest) : option (contract (parameter))) {
+ | Some (contract) => contract;
+ | None => (failwith ("Contract not found.") : contract (parameter));
+ };
(* Reuse the parameter in the subsequent
transaction or use another one, `mock_param`. *)
let mock_param : parameter = Increment (5n);
- let op : operation = Operation.transaction (action, 0mutez, counter);
+ let op : operation = Tezos.transaction (action, 0tez, counter);
([op], store)
};
```
+> Note that `Operation.get_contract` and `Operation.transaction` are
+> *deprecated*.
+
diff --git a/gitlab-pages/docs/advanced/first-contract.md b/gitlab-pages/docs/advanced/first-contract.md
index 00bed6f7c..eb63a25c4 100644
--- a/gitlab-pages/docs/advanced/first-contract.md
+++ b/gitlab-pages/docs/advanced/first-contract.md
@@ -42,59 +42,78 @@ storage value being returned) which in our case is still `Unit`.
Our counter contract will store a single `int` as it's storage, and
will accept an `action` variant in order to re-route our single `main`
-function to two entrypoints for `addition` and `subtraction`.
+function to two entrypoints for `add` (addition) and `sub`
+(subtraction).
```
-type action is
+type parameter is
Increment of int
| Decrement of int
-function main (const p : action ; const s : int) : (list(operation) * int) is
+type storage is int
+
+type return is list (operation) * storage
+
+function add (const n : int; const store : storage) : storage is store + n
+function sub (const n : int; const store : storage) : storage is store - n
+
+function main (const action : parameter; const store : storage) : return is
((nil : list(operation)),
- (case p of
- | Increment (n) -> s + n
- | Decrement (n) -> s - n
- end))
+ case action of
+ Increment (n) -> add (n, store)
+ | Decrement (n) -> sub (n, store)
+ end)
```
```cameligo
-type action =
-| Increment of int
+type parameter =
+ Increment of int
| Decrement of int
-let main (p, s: action * int) : operation list * int =
- let result =
- match p with
- | Increment n -> s + n
- | Decrement n -> s - n
- in
- (([]: operation list), result)
+type storage = int
+
+type return = (operation) list * storage
+
+let add (n, store : int * storage) : storage = store + n
+let sub (n, store : int * storage) : storage = store - n
+
+let main (action, store : parameter * storage) : operation list * storage =
+ (([]: operation list),
+ (match action with
+ Increment n -> add (n, store)
+ | Decrement n -> sub (n, store)))
```
```reasonligo
-type action =
-| Increment(int)
-| Decrement(int);
+type parameter =
+ Increment (int)
+| Decrement (int)
+;
-let main = (p_s: (action, int)) : (list(operation), int) => {
- let p, s = p_s;
- let result =
- switch (p) {
- | Increment(n) => s + n
- | Decrement(n) => s - n
- };
- (([]: list(operation)), result);
-};
+type storage = int;
+
+type return = (list (operation), storage);
+
+let add = ((n, store) : (int, storage)) : storage => store + n;
+let sub = ((n, store) : (int, storage)) : storage => store - n;
+
+let main = ((action, store) : (parameter, storage)) : return =>
+ (([]: list (operation)),
+ (switch (action) {
+ | Increment (n) => add ((n, store))
+ | Decrement (n) => sub ((n, store))
+ }));
```
-To dry-run the counter contract, we will use the `main` entrypoint, provide a variant parameter of `Increment(5)` and an initial storage value of `5`.
-
+To dry-run the counter contract, we will provide the `main` function
+with a variant parameter of value `Increment (5)` and an initial
+storage value of `5`.
@@ -131,39 +150,30 @@ Command above will output the following Michelson code:
{ parameter (or (int %decrement) (int %increment)) ;
storage int ;
code { DUP ;
- CAR ;
- DIP { DUP } ;
- SWAP ;
CDR ;
DIP { DUP } ;
SWAP ;
+ CAR ;
IF_LEFT
{ DUP ;
- DIP 2 { DUP } ;
- DIG 2 ;
- DIP { DUP } ;
+ DIP { DIP { DUP } ; SWAP } ;
+ PAIR ;
+ DUP ;
+ CDR ;
+ DIP { DUP ; CAR } ;
SUB ;
- SWAP ;
- DROP ;
- SWAP ;
- DROP }
+ DIP { DROP 2 } }
{ DUP ;
- DIP 2 { DUP } ;
- DIG 2 ;
- DIP { DUP } ;
+ DIP { DIP { DUP } ; SWAP } ;
+ PAIR ;
+ DUP ;
+ CDR ;
+ DIP { DUP ; CAR } ;
ADD ;
- SWAP ;
- DROP ;
- SWAP ;
- DROP } ;
+ DIP { DROP 2 } } ;
NIL operation ;
PAIR ;
- SWAP ;
- DROP ;
- SWAP ;
- DROP ;
- SWAP ;
- DROP } }
+ DIP { DROP 2 } } }
```
@@ -180,12 +190,15 @@ ligo compile-storage src/counter.ligo main 5
```
-
-In our case the LIGO storage value maps 1:1 to its Michelson representation, however this will not be the case once the parameter is of a more complex data type, like a record.
+In our case the LIGO storage value maps 1:1 to its Michelson
+representation, however this will not be the case once the parameter
+is of a more complex data type, like a record.
## Invoking a LIGO contract
-Same rules apply for parameters, as apply for translating LIGO storage values to Michelson. We will need to use `compile-parameter` to compile our `action` variant into Michelson, here's how:
+Same rules apply for parameters, as apply for translating LIGO storage
+values to Michelson. We will need to use `compile-parameter` to
+compile our `action` variant into Michelson, here's how:
@@ -195,6 +208,5 @@ ligo compile-parameter src/counter.ligo main 'Increment(5)'
```
-
Now we can use `(Right 5)` which is a Michelson value, to invoke our
-contract - e.g. via `tezos-client`
+contract - e.g., via `tezos-client`
diff --git a/gitlab-pages/docs/advanced/src/counter.ligo b/gitlab-pages/docs/advanced/src/counter.ligo
new file mode 100644
index 000000000..301b662c4
--- /dev/null
+++ b/gitlab-pages/docs/advanced/src/counter.ligo
@@ -0,0 +1,17 @@
+type parameter is
+ Increment of int
+| Decrement of int
+
+type storage is int
+
+type return is list (operation) * storage
+
+function add (const n : int; const store : storage) : storage is store + n
+function sub (const n : int; const store : storage) : storage is store - n
+
+function main (const action : parameter; const store : storage) : return is
+ ((nil : list(operation)),
+ case action of
+ Increment (n) -> add (n, store)
+ | Decrement (n) -> sub (n, store)
+ end)
diff --git a/gitlab-pages/docs/advanced/src/functions.ligo b/gitlab-pages/docs/advanced/src/functions.ligo
new file mode 100644
index 000000000..6e0f83bf5
--- /dev/null
+++ b/gitlab-pages/docs/advanced/src/functions.ligo
@@ -0,0 +1,9 @@
+function multiply (const a : int; const b : int) : int is
+ block {
+ const result : int = a * b
+ } with result
+
+function add (const a : int; const b : int) : int is a + b
+
+function main (const p : unit; const s : unit) : list (operation) * unit is
+ ((nil : list (operation)), s)
diff --git a/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo b/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo
new file mode 100644
index 000000000..301b662c4
--- /dev/null
+++ b/gitlab-pages/docs/advanced/src/multiple-entrypoints.ligo
@@ -0,0 +1,17 @@
+type parameter is
+ Increment of int
+| Decrement of int
+
+type storage is int
+
+type return is list (operation) * storage
+
+function add (const n : int; const store : storage) : storage is store + n
+function sub (const n : int; const store : storage) : storage is store - n
+
+function main (const action : parameter; const store : storage) : return is
+ ((nil : list(operation)),
+ case action of
+ Increment (n) -> add (n, store)
+ | Decrement (n) -> sub (n, store)
+ end)
diff --git a/gitlab-pages/docs/advanced/src/variables.ligo b/gitlab-pages/docs/advanced/src/variables.ligo
new file mode 100644
index 000000000..e8e40f1f7
--- /dev/null
+++ b/gitlab-pages/docs/advanced/src/variables.ligo
@@ -0,0 +1,5 @@
+const four : int = 4
+const name : string = "John Doe"
+
+function main (const p : unit; const s : unit) : list (operation) * unit is
+ ((nil : list (operation)), s)
diff --git a/gitlab-pages/docs/advanced/timestamps-addresses.md b/gitlab-pages/docs/advanced/timestamps-addresses.md
index fb2154bc8..b3a4d2391 100644
--- a/gitlab-pages/docs/advanced/timestamps-addresses.md
+++ b/gitlab-pages/docs/advanced/timestamps-addresses.md
@@ -18,23 +18,29 @@ current timestamp value.
```pascaligo group=a
-const today : timestamp = now
+const today : timestamp = Tezos.now
```
+> Note that `now` is *deprecated*.
+
```cameligo group=a
-let today : timestamp = Current.time
+let today : timestamp = Tezos.now
```
+> Note that `Current.time` is *deprecated*.
+
```reasonligo group=a
-let today : timestamp = Current.time;
+let today : timestamp = Tezos.now;
```
+> Note that `Current.time` is *deprecated*.
+
-> When running code, the LIGO CLI option
-> `--predecessor-timestamp` allows you to control what `now` returns.
+> When running code, the LIGO CLI option `--predecessor-timestamp`
+> allows you to control what `Tezos.now` returns.
### Timestamp Arithmetics
@@ -46,31 +52,37 @@ constraints on your smart contracts. Consider the following scenarios.
```pascaligo group=b
-const today : timestamp = now
+const today : timestamp = Tezos.now
const one_day : int = 86400
const in_24_hrs : timestamp = today + one_day
const some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp)
const one_day_later : timestamp = some_date + one_day
```
+> Note that `now` is *deprecated*.
+
```cameligo group=b
-let today : timestamp = Current.time
+let today : timestamp = Tezos.now
let one_day : int = 86400
let in_24_hrs : timestamp = today + one_day
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp)
let one_day_later : timestamp = some_date + one_day
```
+> Note that `Current.time` is *deprecated*.
+
```reasonligo group=b
-let today : timestamp = Current.time;
+let today : timestamp = Tezos.now;
let one_day : int = 86400;
let in_24_hrs : timestamp = today + one_day;
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp);
let one_day_later : timestamp = some_date + one_day;
```
+> Note that `Current.time` is *deprecated*.
+
#### 24 hours Ago
@@ -78,25 +90,32 @@ let one_day_later : timestamp = some_date + one_day;
```pascaligo group=c
-const today : timestamp = now
+const today : timestamp = Tezos.now
const one_day : int = 86400
const in_24_hrs : timestamp = today - one_day
```
+> Note that `now` is *deprecated*.
+
```cameligo group=c
-let today : timestamp = Current.time
+let today : timestamp = Tezos.now
let one_day : int = 86400
let in_24_hrs : timestamp = today - one_day
```
+> Note that `Current.time` is *deprecated*.
+
```reasonligo group=c
-let today : timestamp = Current.time;
+let today : timestamp = Tezos.now;
let one_day : int = 86400;
let in_24_hrs : timestamp = today - one_day;
```
+> Note that `Current.time` is *deprecated*.
+
+
### Comparing Timestamps
@@ -107,19 +126,26 @@ applying to numbers.
```pascaligo group=c
-const not_tommorow : bool = (now = in_24_hrs)
+const not_tommorow : bool = (Tezos.now = in_24_hrs)
```
+> Note that `now` is *deprecated*.
+
```cameligo group=c
-let not_tomorrow : bool = (Current.time = in_24_hrs)
+let not_tomorrow : bool = (Tezos.now = in_24_hrs)
```
+> Note that `Current.time` is *deprecated*.
+
```reasonligo group=c
-let not_tomorrow : bool = (Current.time == in_24_hrs);
+let not_tomorrow : bool = (Tezos.now == in_24_hrs);
```
+> Note that `Current.time` is *deprecated*.
+
+
## Addresses
diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md
index 8f8baebdb..15e10bfe4 100644
--- a/gitlab-pages/docs/api/cheat-sheet.md
+++ b/gitlab-pages/docs/api/cheat-sheet.md
@@ -4,7 +4,7 @@ title: Cheat Sheet
---
-
@@ -30,7 +30,7 @@ Note that this table is not compiled before production and currently needs to be
|Includes|```#include "library.ligo"```|
|Functions (short form)|
function add (const a : int ; const b : int) : int is
block { skip } with a + b
|
|Functions (long form)|
function add (const a : int ; const b : int) : int is
block {
const result: int = a + b;
} with result
|
-| If Statement |
if age < 16
then fail("Too young to drive.");
else const new_id: int = prev_id + 1;
|
+| If Statement |
if age < 16
then fail("Too young to drive.");
else const new_id: int = prev_id + 1;
|
|Options|
type middleName is option(string);
const middleName : middleName = Some("Foo");
const middleName : middleName = None;
|
|Assignment| ```const age: int = 5;```|
|Assignment on an existing variable
*⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` |
@@ -71,8 +71,8 @@ Note that this table is not compiled before production and currently needs to be
|Variant *(pattern)* matching|
let a: action = Increment 5
match a with
| Increment n -> n + 1
| Decrement n -> n - 1
|
|Records|
type person = {
age: int ;
name: string ;
}
let john : person = {
age = 18;
name = "John Doe";
}
let name: string = john.name
|
|Maps|
type prices = (nat, tez) map
let prices : prices = Map.literal [
(10n, 60mutez);
(50n, 30mutez);
(100n, 10mutez)
]
let price: tez option = Map.find_opt 50n prices
let prices: prices = Map.update 200n (Some 5mutez) prices
|
-|Contracts & Accounts|
let destination_address : address = "tz1..."
let contract : unit contract =
Operation.get_contract destination_address
|
-|Transactions|
let payment : operation =
Operation.transaction unit amount receiver
|
+|Contracts & Accounts|
let destination_address : address = "tz1..."
let contract : unit contract =
Tezos.get_contract destination_address
|
+|Transactions|
let payment : operation =
Tezos.transaction unit amount receiver
|
|Exception/Failure|`failwith("Your descriptive error message for the user goes here.")`|
@@ -103,8 +103,8 @@ Note that this table is not compiled before production and currently needs to be
|Variant *(pattern)* matching|
let a: action = Increment(5);
switch(a) {
| Increment(n) => n + 1
| Decrement(n) => n - 1;
}
|
|Records|
type person = {
age: int,
name: string
}
let john : person = {
age: 18,
name: "John Doe"
};
let name: string = john.name;
|
|Maps|
type prices = map(nat, tez);
let prices : prices = Map.literal([
(10n, 60mutez),
(50n, 30mutez),
(100n, 10mutez)
]);
let price: option(tez) = Map.find_opt(50n, prices);
let prices: prices = Map.update(200n, Some (5mutez), prices);
|
-|Contracts & Accounts|
let destination_address : address = "tz1...";
let contract : contract(unit) =
Operation.get_contract(destination_address);
|
-|Transactions|
let payment : operation =
Operation.transaction (unit, amount, receiver);
|
+|Contracts & Accounts|
let destination_address : address = "tz1...";
let contract : contract(unit) =
Tezos.get_contract(destination_address);
|
+|Transactions|
let payment : operation =
Tezos.transaction (unit, amount, receiver);
|
|Exception/Failure|`failwith("Your descriptive error message for the user goes here.");`|
diff --git a/gitlab-pages/docs/language-basics/boolean-if-else.md b/gitlab-pages/docs/language-basics/boolean-if-else.md
index 8a872d777..e9b38291a 100644
--- a/gitlab-pages/docs/language-basics/boolean-if-else.md
+++ b/gitlab-pages/docs/language-basics/boolean-if-else.md
@@ -11,8 +11,8 @@ value:
```pascaligo group=a
-const a : bool = True // Notice the capital letter
-const b : bool = False // Same.
+const a : bool = True // Also: true
+const b : bool = False // Also: false
```
```cameligo group=a
@@ -137,7 +137,7 @@ state.
type magnitude is Small | Large // See variant types.
function compare (const n : nat) : magnitude is
- if n < 10n then Small (Unit) else Large (Unit) // Unit is needed for now.
+ if n < 10n then Small else Large
```
You can run the `compare` function defined above using the LIGO compiler
@@ -145,7 +145,7 @@ like this:
```shell
ligo run-function
gitlab-pages/docs/language-basics/boolean-if-else/cond.ligo compare 21n'
-# Outputs: Large (Unit)
+# Outputs: Large(Unit)
```
When the branches of the conditional are not a single expression, as
@@ -161,7 +161,7 @@ else skip;
```
As an exception to the rule, the blocks in a conditional branch do not
-need to be introduced by the keywor `block`, so, we could have written
+need to be introduced by the keyword `block`, so we could have written
instead:
```pascaligo skip
if x < y then {
@@ -187,9 +187,15 @@ gitlab-pages/docs/language-basics/boolean-if-else/cond.mligo compare 21n'
# Outputs: Large
```
+> Notice that, as in OCaml, in CameLIGO, if a conditional has a branch
+> `else ()`, that branch can be omitted. The resulting so-called
+> *dangling else* problem is parsed by associating any `else` to the
+> closest previous `then`.
+
+
```reasonligo group=e
-type magnitude = | Small | Large; // See variant types.
+type magnitude = Small | Large; // See variant types.
let compare = (n : nat) : magnitude =>
if (n < 10n) { Small; } else { Large; };
diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md
index d0344a754..b4c81beb1 100644
--- a/gitlab-pages/docs/language-basics/functions.md
+++ b/gitlab-pages/docs/language-basics/functions.md
@@ -4,7 +4,15 @@ title: Functions
---
LIGO functions are the basic building block of contracts. For example,
-entrypoints are functions.
+entrypoints are functions and each smart contract needs a main
+function that dispatches control to the entrypoints (it is not already
+the default entrypoint).
+
+The semantics of function calls in LIGO is that of a *copy of the
+arguments but also of the environment*. In the case of PascaLIGO, this
+means that any mutation (assignment) on variables outside the scope of
+the function will be lost when the function returns, just as the
+mutations inside the functions will be.
## Declaring Functions
@@ -230,10 +238,14 @@ function to all its elements.
```pascaligo group=c
function incr_map (const l : list (int)) : list (int) is
- list_map (function (const i : int) : int is i + 1, l)
+ List.map (function (const i : int) : int is i + 1, l)
```
-You can call the function `incr_map` defined above using the LIGO compiler
-like so:
+
+> Note that `list_map` is *deprecated*.
+
+You can call the function `incr_map` defined above using the LIGO
+compiler like so:
+
```shell
ligo run-function
gitlab-pages/docs/language-basics/src/functions/incr_map.ligo incr_map
diff --git a/gitlab-pages/docs/language-basics/loops.md b/gitlab-pages/docs/language-basics/loops.md
index bb31e124f..1ded1ef05 100644
--- a/gitlab-pages/docs/language-basics/loops.md
+++ b/gitlab-pages/docs/language-basics/loops.md
@@ -79,17 +79,21 @@ let gcd (x,y : nat * nat) : nat =
```
To ease the writing and reading of the iterated functions (here,
-`iter`), two predefined functions are provided: `continue` and `stop`:
+`iter`), two predefined functions are provided: `Loop.continue` and
+`Loop.stop`:
```cameligo group=a
let iter (x,y : nat * nat) : bool * (nat * nat) =
- if y = 0n then stop (x,y) else continue (y, x mod y)
+ if y = 0n then Loop.stop (x,y) else Loop.continue (y, x mod y)
let gcd (x,y : nat * nat) : nat =
let x,y = if x < y then y,x else x,y in
let x,y = Loop.fold_while iter (x,y)
in x
```
+
+> Note that `stop` and `continue` are *deprecated*.
+
You can call the function `gcd` defined above using the LIGO compiler
like so:
```shell
@@ -131,11 +135,12 @@ let gcd = ((x,y) : (nat, nat)) : nat => {
```
To ease the writing and reading of the iterated functions (here,
-`iter`), two predefined functions are provided: `continue` and `stop`:
+`iter`), two predefined functions are provided: `Loop.continue` and
+`Loop.stop`:
```reasonligo group=b
let iter = ((x,y) : (nat, nat)) : (bool, (nat, nat)) =>
- if (y == 0n) { stop ((x,y)); } else { continue ((y, x mod y)); };
+ if (y == 0n) { Loop.stop ((x,y)); } else { Loop.continue ((y, x mod y)); };
let gcd = ((x,y) : (nat, nat)) : nat => {
let (x,y) = if (x < y) { (y,x); } else { (x,y); };
@@ -143,6 +148,9 @@ let gcd = ((x,y) : (nat, nat)) : nat => {
x
};
```
+
+> Note that `stop` and `continue` are *deprecated*.
+
## Bounded Loops
diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md
index d691d588e..f1b491b60 100644
--- a/gitlab-pages/docs/language-basics/maps-records.md
+++ b/gitlab-pages/docs/language-basics/maps-records.md
@@ -19,7 +19,7 @@ Let us first consider and example of record type declaration.
-```pascaligo group=a
+```pascaligo group=records1
type user is
record [
id : nat;
@@ -29,7 +29,7 @@ type user is
```
-```cameligo group=a
+```cameligo group=records1
type user = {
id : nat;
is_admin : bool;
@@ -38,7 +38,7 @@ type user = {
```
-```reasonligo group=a
+```reasonligo group=records1
type user = {
id : nat,
is_admin : bool,
@@ -51,7 +51,7 @@ And here is how a record value is defined:
-```pascaligo group=a
+```pascaligo group=records1
const alice : user =
record [
id = 1n;
@@ -61,7 +61,7 @@ const alice : user =
```
-```cameligo group=a
+```cameligo group=records1
let alice : user = {
id = 1n;
is_admin = true;
@@ -70,7 +70,7 @@ let alice : user = {
```
-```reasonligo group=a
+```reasonligo group=records1
let alice : user = {
id : 1n,
is_admin : true,
@@ -86,17 +86,17 @@ operator, like so:
-```pascaligo group=a
+```pascaligo group=records1
const alice_admin : bool = alice.is_admin
```
-```cameligo group=a
+```cameligo group=records1
let alice_admin : bool = alice.is_admin
```
-```reasonligo group=a
+```reasonligo group=records1
let alice_admin : bool = alice.is_admin;
```
@@ -123,7 +123,7 @@ In PascaLIGO, the shape of that expression is `
with
`. The record variable is the record to update and the
record value is the update itself.
-```pascaligo group=b
+```pascaligo group=records2
type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int]
@@ -151,7 +151,7 @@ the blockless function.
The syntax for the functional updates of record in CameLIGO follows
that of OCaml:
-```cameligo group=b
+```cameligo group=records2
type point = {x : int; y : int; z : int}
type vector = {dx : int; dy : int}
@@ -179,7 +179,7 @@ xy_translate "({x=2;y=3;z=1}, {dx=3;dy=4})"
The syntax for the functional updates of record in ReasonLIGO follows
that of ReasonML:
-```reasonligo group=b
+```reasonligo group=records2
type point = {x : int, y : int, z : int};
type vector = {dx : int, dy : int};
@@ -216,7 +216,7 @@ name "patch").
Let us consider defining a function that translates three-dimensional
points on a plane.
-```pascaligo group=c
+```pascaligo group=records3
type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int]
@@ -242,7 +242,7 @@ Of course, we can actually translate the point with only one `patch`,
as the previous example was meant to show that, after the first patch,
the value of `p` indeed changed. So, a shorter version would be
-```pascaligo group=d
+```pascaligo group=records4
type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int]
@@ -267,7 +267,7 @@ Record patches can actually be simulated with functional updates. All
we have to do is *declare a new record value with the same name as the
one we want to update* and use a functional update, like so:
-```pascaligo group=e
+```pascaligo group=records5
type point is record [x : int; y : int; z : int]
type vector is record [dx : int; dy : int]
@@ -298,71 +298,98 @@ values of the same type. The former are called *key* and the latter
is that the type of the keys must be *comparable*, in the Michelson
sense.
+### Declaring a Map
+
Here is how a custom map from addresses to a pair of integers is
defined.
+
-```pascaligo group=f
+```pascaligo group=maps
type move is int * int
type register is map (address, move)
```
-```cameligo group=f
+```cameligo group=maps
type move = int * int
type register = (address, move) map
```
-```reasonligo group=f
+```reasonligo group=maps
type move = (int, int);
type register = map (address, move);
```
-And here is how a map value is defined:
+### Creating an Empty Map
+
+Here is how to create an empty map.
+
+
+
+
+```pascaligo group=maps
+const empty : register = map []
+```
+
+
+```cameligo group=maps
+let empty : register = Map.empty
+```
+
+
+```reasonligo group=maps
+let empty : register = Map.empty
+```
+
+
+### Creating a Non-empty Map
+
+And here is how to create a non-empty map value:
-```pascaligo group=f
+```pascaligo group=maps
const moves : register =
map [
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2);
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)]
```
-> Notice the `->` between the key and its value and `;` to separate
-> individual map entries. The annotated value `("" :
-> address)` means that we cast a string into an address. Also, `map`
-> is a keyword.
+Notice the `->` between the key and its value and `;` to separate
+individual map entries. The annotated value `("" :
+address)` means that we cast a string into an address. Also, `map` is
+a keyword.
-```cameligo group=f
+```cameligo group=maps
let moves : register =
Map.literal [
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))]
```
-> The `Map.literal` predefined function builds a map from a list of
-> key-value pair tuples, `(, )`. Note also the `;` to
-> separate individual map entries. `("": address)`
-> means that we type-cast a string into an address.
+The `Map.literal` predefined function builds a map from a list of
+key-value pair tuples, `(, )`. Note also the `;` to
+separate individual map entries. `("": address)` means
+that we type-cast a string into an address. -->
-```reasonligo group=f
+```reasonligo group=maps
let moves : register =
Map.literal ([
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)),
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, (0,3))]);
```
-> The `Map.literal` predefined function builds a map from a list of
-> key-value pair tuples, `(, )`. Note also the `;` to
-> separate individual map entries. `("": address)`
-> means that we type-cast a string into an address.
+The `Map.literal` predefined function builds a map from a list of
+key-value pair tuples, `(, )`. Note also the `;` to
+separate individual map entries. `("": address)` means
+that we type-cast a string into an address. -->
@@ -375,19 +402,19 @@ In PascaLIGO, we can use the postfix `[]` operator to read the `move`
value associated to a given key (`address` here) in the register. Here
is an example:
-```pascaligo group=f
+```pascaligo group=maps
const my_balance : option (move) =
moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)]
```
-```cameligo group=f
+```cameligo group=maps
let my_balance : move option =
Map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves
```
-```reasonligo group=f
+```reasonligo group=maps
let my_balance : option (move) =
Map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves);
```
@@ -400,7 +427,7 @@ the reader to account for a missing key in the map. This requires
-```pascaligo group=f
+```pascaligo group=maps
function force_access (const key : address; const moves : register) : move is
case moves[key] of
Some (move) -> move
@@ -409,7 +436,7 @@ function force_access (const key : address; const moves : register) : move is
```
-```cameligo group=f
+```cameligo group=maps
let force_access (key, moves : address * register) : move =
match Map.find_opt key moves with
Some move -> move
@@ -417,7 +444,7 @@ let force_access (key, moves : address * register) : move =
```
-```reasonligo group=f
+```reasonligo group=maps
let force_access = ((key, moves) : (address, register)) : move => {
switch (Map.find_opt (key, moves)) {
| Some (move) => move
@@ -443,7 +470,7 @@ The values of a PascaLIGO map can be updated using the usual
assignment syntax `