Merge branch 'doc-failwith' into 'dev'

Documentation improvements

See merge request ligolang/ligo!666
This commit is contained in:
Sander 2020-06-11 09:28:19 +00:00
commit c6ad617524
10 changed files with 366 additions and 295 deletions

View File

@ -1,6 +1,6 @@
---
id: loops
title: Loops
title: Iteration
---
import Syntax from '@theme/Syntax';
@ -110,6 +110,7 @@ let gcd = ((x,y) : (nat, nat)) : nat => {
</Syntax>
<Syntax syntax="pascaligo">
## Bounded Loops
@ -212,3 +213,5 @@ gitlab-pages/docs/language-basics/src/loops/collection.ligo sum_map
'map ["1"->1; "2"->2; "3"->3]'
# Outputs: ( "123", 6 )
```
</Syntax>

View File

@ -13,55 +13,9 @@ Lazily means that storage is read or written per key on demand. Therefore
there are no `map`, `fold`, and `iter` operations as in
[Map](./map-reference).
The gast costs of big maps are higher than standard maps as data is lazily
The gas costs of big maps are higher than standard maps as data is lazily
deserialized.
<SyntaxTitle syntax="pascaligo">
type big_map ('key, 'value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type big_map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo">
The type of a big map from values of type `key` to
values of type `value` is `big_map (key, value)`.
```pascaligo group=big_map
type move is int * int
type register is big_map (address, move)
```
</Syntax>
<Syntax syntax="cameligo">
The type of a big map from values of type `key` to values
of type `value` is `(key, value) big_map`.
```cameligo group=big_map
type move = int * int
type register = (address, move) big_map
```
</Syntax>
<Syntax syntax="reasonligo">
The type of a big map from values of type `key` to
values of type `value` is `big_map(key, value)`.
```reasonligo group=big_map
type move = (int, int);
type register = big_map(address, move);
```
</Syntax>
Be aware that a `big_map` cannot appear inside another `big_map`.
<SyntaxTitle syntax="pascaligo">
function empty : big_map ('key, 'value)
</SyntaxTitle>
@ -77,6 +31,9 @@ Create an empty big_map.
<Syntax syntax="pascaligo">
```pascaligo group=big_map
type move is int * int
type register is big_map (address, move)
const empty : register = Big_map.empty
```
@ -90,6 +47,9 @@ const empty_alternative : register = big_map []
<Syntax syntax="cameligo">
```cameligo group=big_map
type move = int * int
type register = (address, move) big_map
let empty : register = Big_map.empty
```
@ -97,6 +57,9 @@ let empty : register = Big_map.empty
<Syntax syntax="reasonligo">
```reasonligo group=big_map
type move = (int, int);
type register = big_map(address, move);
let empty: register = Big_map.empty
```

View File

@ -8,16 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
function concat : bytes -> bytes -> bytes
</SyntaxTitle>

View File

@ -8,42 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type key
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type key
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type key
</SyntaxTitle>
A public cryptographic key.
<SyntaxTitle syntax="pascaligo">
type key_hash
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type key_hash
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type key_hash
</SyntaxTitle>
The hash of a public cryptographic key.
<SyntaxTitle syntax="pascaligo">
type signature
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type signature
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type signature
</SyntaxTitle>
A cryptographic signature.
<SyntaxTitle syntax="pascaligo">
function blake2b : bytes -> bytes
</SyntaxTitle>

View File

@ -8,80 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type timestamp
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type timestamp
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type timestamp
</SyntaxTitle>
A date in the real world.
<SyntaxTitle syntax="pascaligo">
type tez
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type tez
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type tez
</SyntaxTitle>
A specific type for tokens.
<SyntaxTitle syntax="pascaligo">
type address
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type address
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type address
</SyntaxTitle>
An untyped address which can refer to a smart contract or account.
<SyntaxTitle syntax="pascaligo">
type contract('parameter)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 'parameter contract
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type contract('parameter)
</SyntaxTitle>
A typed contract.
Use `unit` as `parameter` to indicate an implicit account.
<SyntaxTitle syntax="pascaligo">
type operation
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type operation
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type operation
</SyntaxTitle>
An operation emitted by the contract
<SyntaxTitle syntax="pascaligo">
type chain_id
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type chain_id
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type chain_id
</SyntaxTitle>
The identifier of a chain, used to indicate test or main chains.
<SyntaxTitle syntax="pascaligo">
function balance : tez
</SyntaxTitle>
@ -94,8 +20,6 @@ let balance: tez
Get the balance for the contract.
<Syntax syntax="pascaligo">
```pascaligo
@ -598,53 +522,17 @@ let main = (p : unit) : address => Tezos.source;
<SyntaxTitle syntax="pascaligo">
function failwith : string -> unit
function failwith : 'a -> unit
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
function failwith : string -> unit
function failwith : 'a -> unit
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
function failwith : string -> unit
function failwith: 'a -> unit
</SyntaxTitle>
Cause the contract to fail with an error message.
[See `failwith`](toplevel.md#failwith)
> ⚠ Using this currently requires in general a type annotation on the
> `failwith` call.
<Syntax syntax="cameligo">
Note that `Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="reasonligo">
Note that `Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="pascaligo">
```pascaligo
function main (const p : int; const s : unit) : list (operation) * unit is
block {
if p > 10 then failwith ("Failure.") else skip
}
with ((nil : list (operation)), s)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let main (p,s : int * unit) = if p > 10 then failwith "Failure."
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let main = ((p,s) : (int, unit)) =>
if (p > 10) { failwith ("Failure."); };
```
</Syntax>
<SyntaxTitle syntax="pascaligo">
function chain_id : chain_id

View File

@ -8,18 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type list ('t)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 't list
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type list('t)
</SyntaxTitle>
A sequence of elements of the same type.
<SyntaxTitle syntax="pascaligo">
function length : nat
</SyntaxTitle>

View File

@ -8,50 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type map ('key, 'value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type ('key, 'value) map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo">
The type of a map from values of type `key` to
values of type `value` is `map (key, value)`.
```pascaligo group=maps
type move is int * int
type register is map (address, move)
```
</Syntax>
<Syntax syntax="cameligo">
The type of a map from values of type `key` to values
of type `value` is `(key, value) map`.
```cameligo group=maps
type move = int * int
type register = (address, move) map
```
</Syntax>
<Syntax syntax="reasonligo">
The type of a map from values of type `key` to
values of type `value` is `map (key, value)`.
```reasonligo group=maps
type move = (int, int);
type register = map (address, move);
```
</Syntax>
<SyntaxTitle syntax="pascaligo">
function empty : map ('key, 'value)
</SyntaxTitle>
@ -67,6 +23,9 @@ Create an empty map.
<Syntax syntax="pascaligo">
```pascaligo group=maps
type move is int * int
type register is map (address, move)
const empty : register = Map.empty
```
@ -80,6 +39,9 @@ const empty : register = map []
<Syntax syntax="cameligo">
```cameligo group=maps
type move = int * int
type register = (address, move) map
let empty : register = Map.empty
```
@ -87,6 +49,9 @@ let empty : register = Map.empty
<Syntax syntax="reasonligo">
```reasonligo group=maps
type move = (int, int);
type register = map (address, move);
let empty : register = Map.empty
```

View File

@ -10,16 +10,6 @@ import SyntaxTitle from '@theme/SyntaxTitle';
Sets are unordered collections of unique values of the same type.
<SyntaxTitle syntax="pascaligo">
type set ('value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 'value set
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type set('value)
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
function empty : set('value)
</SyntaxTitle>

View File

@ -8,18 +8,6 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
type string
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type string
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type string
</SyntaxTitle>
A sequence of characters.
<SyntaxTitle syntax="pascaligo">
function length : string -> nat
</SyntaxTitle>

View File

@ -8,7 +8,303 @@ hide_table_of_contents: true
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
These functions are available without any needed prefix.
These types and functions are available without any needed prefix.
<SyntaxTitle syntax="pascaligo">
type address
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type address
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type address
</SyntaxTitle>
An untyped address which can refer to a smart contract or account.
<SyntaxTitle syntax="pascaligo">
type big_map ('key, 'value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type big_map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo">
The type of a big map from values of type `key` to
values of type `value` is `big_map (key, value)`.
```pascaligo group=big_map
type move is int * int
type register is big_map (address, move)
```
</Syntax>
<Syntax syntax="cameligo">
The type of a big map from values of type `key` to values
of type `value` is `(key, value) big_map`.
```cameligo group=big_map
type move = int * int
type register = (address, move) big_map
```
</Syntax>
<Syntax syntax="reasonligo">
The type of a big map from values of type `key` to
values of type `value` is `big_map(key, value)`.
```reasonligo group=big_map
type move = (int, int);
type register = big_map(address, move);
```
</Syntax>
Be aware that a `big_map` cannot appear inside another `big_map`.
<SyntaxTitle syntax="pascaligo">
type bool
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type bool
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type bool
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type bytes
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
type contract('parameter)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 'parameter contract
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type contract('parameter)
</SyntaxTitle>
A typed contract.
Use `unit` as `parameter` to indicate an implicit account.
<SyntaxTitle syntax="pascaligo">
type chain_id
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type chain_id
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type chain_id
</SyntaxTitle>
The identifier of a chain, used to indicate test or main chains.
<SyntaxTitle syntax="pascaligo">
type int
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type int
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type int
</SyntaxTitle>
An integer.
The only size limit to integers is gas.
<SyntaxTitle syntax="pascaligo">
type key
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type key
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type key
</SyntaxTitle>
A public cryptographic key.
<SyntaxTitle syntax="pascaligo">
type key_hash
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type key_hash
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type key_hash
</SyntaxTitle>
The hash of a public cryptographic key.
<SyntaxTitle syntax="pascaligo">
type list ('t)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 't list
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type list('t)
</SyntaxTitle>
A sequence of elements of the same type.
<SyntaxTitle syntax="pascaligo">
type map ('key, 'value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type ('key, 'value) map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo">
The type of a map from values of type `key` to
values of type `value` is `map (key, value)`.
```pascaligo group=maps
type move is int * int
type register is map (address, move)
```
</Syntax>
<Syntax syntax="cameligo">
The type of a map from values of type `key` to values
of type `value` is `(key, value) map`.
```cameligo group=maps
type move = int * int
type register = (address, move) map
```
</Syntax>
<Syntax syntax="reasonligo">
The type of a map from values of type `key` to
values of type `value` is `map (key, value)`.
```reasonligo group=maps
type move = (int, int);
type register = map (address, move);
```
</Syntax>
<SyntaxTitle syntax="pascaligo">
type nat
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type nat
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type nat
</SyntaxTitle>
A natural number.
The only size limit to natural numbers is gas.
<SyntaxTitle syntax="pascaligo">
type operation
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type operation
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type operation
</SyntaxTitle>
An operation emitted by the contract
<SyntaxTitle syntax="pascaligo">
type set ('value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type 'value set
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type set('value)
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
type signature
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type signature
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type signature
</SyntaxTitle>
A cryptographic signature.
<SyntaxTitle syntax="pascaligo">
type string
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type string
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type string
</SyntaxTitle>
A sequence of characters.
<SyntaxTitle syntax="pascaligo">
type tez
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type tez
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type tez
</SyntaxTitle>
A specific type for tokens.
<SyntaxTitle syntax="pascaligo">
type timestamp
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type timestamp
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type timestamp
</SyntaxTitle>
A date in the real world.
<SyntaxTitle syntax="pascaligo">
type unit
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type unit
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type unit
</SyntaxTitle>
<SyntaxTitle syntax="pascaligo">
function is_nat: int -> option(nat)
@ -60,20 +356,56 @@ let (): unit
A helper to create a unit.
<a name="failwith"></a>
<SyntaxTitle syntax="pascaligo">
function failwith : string -> unit
function failwith : 'a -> unit
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val failwith : string -> unit
val failwith : 'a -> unit
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let failwith: string => unit
let failwith: 'a => unit
</SyntaxTitle>
Cause the contract to fail with an error message.
Cause the contract to fail with an error message or integer. Other types are
not supported at the moment.
Using this currently requires in general a type annotation on the
`failwith` call.
<Syntax syntax="pascaligo">
```pascaligo
function main (const p : int; const s : unit) : list (operation) * unit is
block {
if p > 10 then failwith ("Failure.") else skip
}
with ((nil : list (operation)), s)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let main (p,s : int * unit) = if p > 10 then failwith "Failure."
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let main = ((p,s) : (int, unit)) =>
if (p > 10) { failwith ("Failure."); };
```
</Syntax>
<Syntax syntax="cameligo">
`Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
<Syntax syntax="reasonligo">
`Current.failwith` is deprecated. Use `Tezos.failwith` or `failwith` instead.
</Syntax>
> ⚠ Using this currently requires in general a type annotation on the
> `failwith` call.
<SyntaxTitle syntax="pascaligo">
function assert : bool -> unit