Merge branch 'remaining-460-docs' into 'dev'

Remaining doc changes of #460

See merge request ligolang/ligo!505
This commit is contained in:
Sander 2020-03-26 17:08:47 +00:00
commit c28a0f0a60
5 changed files with 61 additions and 37 deletions

View File

@ -234,7 +234,7 @@ function deny (const action : parameter; const store : storage) : return is
else ((nil : list (operation)), store) else ((nil : list (operation)), store)
``` ```
> Note that `amount` is *deprecated*. > Note that `amount` is *deprecated*. Please use `Tezos.amount`.
</Syntax> </Syntax>
@ -251,7 +251,7 @@ let deny (action, store : parameter * storage) : return =
else (([] : operation list), store) else (([] : operation list), store)
``` ```
> Note that `amount` is *deprecated*. > Note that `amount` is *deprecated*. Please use `Tezos.amount`.
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
@ -268,7 +268,7 @@ let deny = ((action, store): (parameter, storage)) : return => {
}; };
``` ```
> Note that `amount` is *deprecated*. > Note that `amount` is *deprecated*. Please use `Tezos.amount`.
</Syntax> </Syntax>
@ -289,7 +289,7 @@ function main (const action : parameter; const store : storage) : return is
else ((nil : list (operation)), store) else ((nil : list (operation)), store)
``` ```
> Note that `source` is *deprecated*. > Note that `source` is *deprecated*. Please use `Tezos.source`.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
@ -302,7 +302,7 @@ let main (action, store: parameter * storage) : return =
else (([] : operation list), store) else (([] : operation list), store)
``` ```
> Note that `source` is *deprecated*. > Note that `source` is *deprecated*. Please use `Tezos.source`.
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
@ -316,7 +316,7 @@ let main = ((action, store) : (parameter, storage)) : return => {
}; };
``` ```
> Note that `source` is *deprecated*. > Note that `source` is *deprecated*. Please use `Tezos.source`.
</Syntax> </Syntax>

View File

@ -11,13 +11,13 @@ LIGO features timestamps, as Michelson does, while bakers baking the
block (including the transaction in a block) are responsible for block (including the transaction in a block) are responsible for
providing the given current timestamp for the contract. providing the given current timestamp for the contract.
### Current Time ### Starting time of the current block
You can obtain the current time using the built-in syntax specific You can obtain the starting time of the current block using the
expression, please be aware that it is up to the baker to set the built-in `Tezos.now`. This timestamp does not change during the execution
of the contract. Please be aware that it is up to the baker to set the
current timestamp value. current timestamp value.
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=a ```pascaligo group=a
@ -62,20 +62,20 @@ constraints on your smart contracts. Consider the following scenarios.
```pascaligo group=b ```pascaligo group=b
const today : timestamp = Tezos.now const today : timestamp = Tezos.now
const one_day : int = 86400 const one_day : int = 86_400
const in_24_hrs : timestamp = today + one_day const in_24_hrs : timestamp = today + one_day
const some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp) const some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp)
const one_day_later : timestamp = some_date + one_day const one_day_later : timestamp = some_date + one_day
``` ```
> Note that `now` is *deprecated*. > Note that `now` is *deprecated*. Please use `Tezos.now`.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=b ```cameligo group=b
let today : timestamp = Tezos.now let today : timestamp = Tezos.now
let one_day : int = 86400 let one_day : int = 86_400
let in_24_hrs : timestamp = today + one_day let in_24_hrs : timestamp = today + one_day
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp) let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp)
let one_day_later : timestamp = some_date + one_day let one_day_later : timestamp = some_date + one_day
@ -88,7 +88,7 @@ let one_day_later : timestamp = some_date + one_day
```reasonligo group=b ```reasonligo group=b
let today : timestamp = Tezos.now; let today : timestamp = Tezos.now;
let one_day : int = 86400; let one_day : int = 86_400;
let in_24_hrs : timestamp = today + one_day; let in_24_hrs : timestamp = today + one_day;
let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp); let some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp);
let one_day_later : timestamp = some_date + one_day; let one_day_later : timestamp = some_date + one_day;
@ -110,7 +110,7 @@ const one_day : int = 86400
const in_24_hrs : timestamp = today - one_day const in_24_hrs : timestamp = today - one_day
``` ```
> Note that `now` is *deprecated*. > Note that `now` is *deprecated*. Please use `Tezos.now`.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
@ -149,7 +149,7 @@ applying to numbers.
const not_tommorow : bool = (Tezos.now = in_24_hrs) const not_tommorow : bool = (Tezos.now = in_24_hrs)
``` ```
> Note that `now` is *deprecated*. > Note that `now` is *deprecated*. Please use `Tezos.now`.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">

View File

@ -959,12 +959,23 @@ The values of a PascaLIGO big map can be updated using the
assignment syntax for ordinary maps assignment syntax for ordinary maps
```pascaligo group=big_maps ```pascaligo group=big_maps
function add (var m : register) : register is function assign (var m : register) : register is
block { block {
m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9)
} with m } with m
```
const updated_map : register = add (moves) If multiple bindings need to be updated, PascaLIGO offers a *patch
instruction* for maps, similar to that for records.
```pascaligo group=big_maps
function assignments (var m : register) : register is
block {
patch m with map [
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (4,9);
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2)
]
} with m
``` ```
</Syntax> </Syntax>

View File

@ -71,16 +71,17 @@ let full_greeting : string = greeting ++ " " ++ name;
## Slicing Strings ## Extracting Subtrings
Strings can be sliced using a built-in function:
Substrings can be extracted using the predefined function
`String.sub`. The first character has index 0 and the interval of
indices for the substring has inclusive bounds.
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=b ```pascaligo group=b
const name : string = "Alice" const name : string = "Alice"
const slice : string = String.slice (0n, 1n, name) const slice : string = String.sub (0n, 1n, name)
``` ```
> Note that `string_slide` is *deprecated*. > Note that `string_slide` is *deprecated*.
@ -90,17 +91,21 @@ const slice : string = String.slice (0n, 1n, name)
```cameligo group=b ```cameligo group=b
let name : string = "Alice" let name : string = "Alice"
let slice : string = String.slice 0n 1n name let slice : string = String.sub 0n 1n name
``` ```
> Note that `String.slice` is *deprecated*.
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=b ```reasonligo group=b
let name : string = "Alice"; let name : string = "Alice";
let slice : string = String.slice (0n, 1n, name); let slice : string = String.sub (0n, 1n, name);
``` ```
> Note that `String.slice` is *deprecated*.
</Syntax> </Syntax>
@ -119,23 +124,27 @@ const name : string = "Alice"
const length : nat = String.length (name) // length = 5 const length : nat = String.length (name) // length = 5
``` ```
> Note that `size` is *deprecated*. > Note that `size` is *deprecated*.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=c ```cameligo group=c
let name : string = "Alice" let name : string = "Alice"
let length : nat = String.size name // length = 5 let length : nat = String.length name // length = 5
``` ```
> Note that `String.size` is *deprecated*.
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=c ```reasonligo group=c
let name : string = "Alice"; let name : string = "Alice";
let length : nat = String.size (name); // length == 5 let length : nat = String.length (name); // length == 5
``` ```
> Note that `String.size` is *deprecated*.
</Syntax> </Syntax>

View File

@ -11,10 +11,11 @@ functions. This page will tell you about them.
## Pack and Unpack ## Pack and Unpack
Michelson provides the `PACK` and `UNPACK` instructions for data As Michelson provides the `PACK` and `UNPACK` instructions for data
serialization. The former converts Michelson data structures into a serialization, so does LIGO with `Bytes.pack` and `Bytes.unpack`. The
binary format, and the latter reverses that transformation. This former serializes Michelson data structures into a binary format, and
functionality can be accessed from within LIGO. the latter reverses that transformation. Unpacking may fail, so the
return type of `Byte.unpack` is an option that needs to be annotated.
> ⚠️ `PACK` and `UNPACK` are Michelson instructions that are intended > ⚠️ `PACK` and `UNPACK` are Michelson instructions that are intended
> to be used by people that really know what they are doing. There are > to be used by people that really know what they are doing. There are
@ -28,11 +29,11 @@ functionality can be accessed from within LIGO.
```pascaligo group=a ```pascaligo group=a
function id_string (const p : string) : option (string) is block { function id_string (const p : string) : option (string) is block {
const packed : bytes = bytes_pack (p) const packed : bytes = Bytes.pack (p)
} with (Bytes.unpack (packed) : option (string)) } with (Bytes.unpack (packed) : option (string))
``` ```
> Note that `bytes_unpack` is *deprecated*. > Note that `bytes_pack` and `bytes_unpack` are *deprecated*.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
@ -72,18 +73,21 @@ a predefined functions returning a value of type `key_hash`.
function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is
block { block {
var ret : bool := False; var ret : bool := False;
var kh2 : key_hash := crypto_hash_key (k2); var kh2 : key_hash := Crypto.hash_key (k2);
if kh1 = kh2 then ret := True else skip if kh1 = kh2 then ret := True else skip
} with (ret, kh2) } with (ret, kh2)
``` ```
> Note that `hash_key` is *deprecated*. Please use `Crypto.hash_key`.
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=b ```cameligo group=b
let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash = let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash =
let kh2 : key_hash = Crypto.hash_key k2 in let kh2 : key_hash = Crypto.hash_key k2 in
if kh1 = kh2 then true, kh2 else false, kh2 (kh1 = kh2), kh2
``` ```
</Syntax> </Syntax>
@ -92,7 +96,7 @@ let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash =
```reasonligo group=b ```reasonligo group=b
let check_hash_key = ((kh1, k2) : (key_hash, key)) : (bool, key_hash) => { let check_hash_key = ((kh1, k2) : (key_hash, key)) : (bool, key_hash) => {
let kh2 : key_hash = Crypto.hash_key (k2); let kh2 : key_hash = Crypto.hash_key (k2);
if (kh1 == kh2) { (true, kh2); } else { (false, kh2); } ((kh1 == kh2), kh2);
}; };
``` ```