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

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
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
expression, please be aware that it is up to the baker to set the
You can obtain the starting time of the current block using 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.
<Syntax syntax="pascaligo">
```pascaligo group=a
@ -62,20 +62,20 @@ constraints on your smart contracts. Consider the following scenarios.
```pascaligo group=b
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 some_date : timestamp = ("2000-01-01T10:10:10Z" : timestamp)
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="cameligo">
```cameligo group=b
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 some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp)
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
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 some_date : timestamp = ("2000-01-01t10:10:10Z" : timestamp);
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
```
> Note that `now` is *deprecated*.
> Note that `now` is *deprecated*. Please use `Tezos.now`.
</Syntax>
<Syntax syntax="cameligo">
@ -149,7 +149,7 @@ applying to numbers.
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="cameligo">

View File

@ -959,12 +959,23 @@ The values of a PascaLIGO big map can be updated using the
assignment syntax for ordinary maps
```pascaligo group=big_maps
function add (var m : register) : register is
function assign (var m : register) : register is
block {
m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9)
} 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>

View File

@ -71,16 +71,17 @@ let full_greeting : string = greeting ++ " " ++ name;
## Slicing Strings
Strings can be sliced using a built-in function:
## Extracting Subtrings
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">
```pascaligo group=b
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*.
@ -90,17 +91,21 @@ const slice : string = String.slice (0n, 1n, name)
```cameligo group=b
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="reasonligo">
```reasonligo group=b
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>
@ -119,23 +124,27 @@ const name : string = "Alice"
const length : nat = String.length (name) // length = 5
```
> Note that `size` is *deprecated*.
> Note that `size` is *deprecated*.
</Syntax>
<Syntax syntax="cameligo">
```cameligo group=c
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="reasonligo">
```reasonligo group=c
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>

View File

@ -11,10 +11,11 @@ functions. This page will tell you about them.
## Pack and Unpack
Michelson provides the `PACK` and `UNPACK` instructions for data
serialization. The former converts Michelson data structures into a
binary format, and the latter reverses that transformation. This
functionality can be accessed from within LIGO.
As Michelson provides the `PACK` and `UNPACK` instructions for data
serialization, so does LIGO with `Bytes.pack` and `Bytes.unpack`. The
former serializes Michelson data structures into a binary format, and
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
> 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
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))
```
> Note that `bytes_unpack` is *deprecated*.
> Note that `bytes_pack` and `bytes_unpack` are *deprecated*.
</Syntax>
<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
block {
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
} with (ret, kh2)
```
> Note that `hash_key` is *deprecated*. Please use `Crypto.hash_key`.
</Syntax>
<Syntax syntax="cameligo">
```cameligo group=b
let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash =
let kh2 : key_hash = Crypto.hash_key k2 in
if kh1 = kh2 then true, kh2 else false, kh2
let kh2 : key_hash = Crypto.hash_key k2 in
(kh1 = kh2), kh2
```
</Syntax>
@ -92,7 +96,7 @@ let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash =
```reasonligo group=b
let check_hash_key = ((kh1, k2) : (key_hash, key)) : (bool, key_hash) => {
let kh2 : key_hash = Crypto.hash_key (k2);
if (kh1 == kh2) { (true, kh2); } else { (false, kh2); }
((kh1 == kh2), kh2);
};
```