From 35ae307f6c262b9b26cdeac8e67e6db98295957d Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Tue, 17 Mar 2020 16:05:03 +0100 Subject: [PATCH] More language-basics changes. --- .../docs/advanced/entrypoints-contracts.md | 12 ++++----- .../docs/advanced/timestamps-addresses.md | 20 +++++++------- gitlab-pages/docs/api/cheat-sheet.md | 9 ++++--- .../docs/language-basics/maps-records.md | 15 +++++++++-- gitlab-pages/docs/language-basics/strings.md | 27 ++++++++++++------- .../docs/language-basics/tezos-specific.md | 24 ++++++++++------- 6 files changed, 67 insertions(+), 40 deletions(-) diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index c2232e494..4073cc1f7 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -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`. @@ -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`. @@ -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`. @@ -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`. @@ -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`. @@ -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`. diff --git a/gitlab-pages/docs/advanced/timestamps-addresses.md b/gitlab-pages/docs/advanced/timestamps-addresses.md index 30f0b55b0..0228b8adf 100644 --- a/gitlab-pages/docs/advanced/timestamps-addresses.md +++ b/gitlab-pages/docs/advanced/timestamps-addresses.md @@ -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. - ```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`. ```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`. @@ -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`. diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 412ba5bd5..712055cfe 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -23,7 +23,8 @@ Note that this table is not compiled before production and currently needs to be |Unit| `unit`| |Boolean|
const hasDriversLicense: bool = False;
const adult: bool = True;
| |Boolean Logic|
(not True) == False == (False and True) == (False or False)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | +|Tez | `3tez`, `3_000tez`, `3.5tez`| +|Mutez (millionth of a tez)| `42000mutez`, `70_000mutez` | |Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`| |Addition |`3 + 4`, `3n + 4n`| |Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| @@ -58,7 +59,8 @@ Note that this table is not compiled before production and currently needs to be |Unit| `unit`| |Boolean|
let has_drivers_license: bool = false
let adult: bool = true
| |Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | +|Tez | `3tez`, `3_000tez`, `3.5tez`| +|Mutez (millionth of a tez)| `42000mutez`, `70_000mutez` | |Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| |Addition |`3 + 4`, `3n + 4n`| |Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| @@ -91,7 +93,8 @@ Note that this table is not compiled before production and currently needs to be |Unit| `unit`| |Boolean|
let has_drivers_license: bool = false;
let adult: bool = true;
| |Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | +|Tez | `3tez`, `3_000tez`, `3.5tez`| +|Mutez (millionth of a tez)| `42000mutez`, `70_000mutez` | |Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| |Addition |`3 + 4`, `3n + 4n`| |Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| diff --git a/gitlab-pages/docs/language-basics/maps-records.md b/gitlab-pages/docs/language-basics/maps-records.md index 837290d39..1f49d318c 100644 --- a/gitlab-pages/docs/language-basics/maps-records.md +++ b/gitlab-pages/docs/language-basics/maps-records.md @@ -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 ```
diff --git a/gitlab-pages/docs/language-basics/strings.md b/gitlab-pages/docs/language-basics/strings.md index be1e201c9..7ae818a79 100644 --- a/gitlab-pages/docs/language-basics/strings.md +++ b/gitlab-pages/docs/language-basics/strings.md @@ -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. ```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*. + ```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*. + @@ -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*. ```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*. + ```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*. + diff --git a/gitlab-pages/docs/language-basics/tezos-specific.md b/gitlab-pages/docs/language-basics/tezos-specific.md index a73698fd6..2e9d347d3 100644 --- a/gitlab-pages/docs/language-basics/tezos-specific.md +++ b/gitlab-pages/docs/language-basics/tezos-specific.md @@ -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*. @@ -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`. + + ```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 ``` @@ -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); }; ```