Merge branch 'feature/LIGO-258-update-docs' into 'dev'
LIGO-258 Docs updates Closes LIGO-258 See merge request ligolang/ligo!272
This commit is contained in:
commit
df584c7006
@ -220,7 +220,7 @@ In our case, we have a `counter.ligo` contract that accepts a parameter of type
|
|||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
```pascaligo
|
```pascaligo skip
|
||||||
// counter.ligo
|
// counter.ligo
|
||||||
type action is
|
type action is
|
||||||
| Increment of int
|
| Increment of int
|
||||||
|
@ -139,21 +139,8 @@ Conditional logic is an important part of every real world program.
|
|||||||
```pascaligo group=e
|
```pascaligo group=e
|
||||||
const min_age: nat = 16n;
|
const min_age: nat = 16n;
|
||||||
|
|
||||||
(*
|
|
||||||
This function is really obnoxious, but it showcases
|
|
||||||
how the if statement and it's syntax can be used.
|
|
||||||
|
|
||||||
Normally, you'd use `with (age > min_age)` instead.
|
|
||||||
*)
|
|
||||||
function is_adult(const age: nat): bool is
|
function is_adult(const age: nat): bool is
|
||||||
block {
|
if (age > min_age) then True else False
|
||||||
var is_adult: bool := False;
|
|
||||||
if (age > min_age) then begin
|
|
||||||
is_adult := True;
|
|
||||||
end else begin
|
|
||||||
is_adult := False;
|
|
||||||
end
|
|
||||||
} with is_adult
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> You can run the function above with
|
> You can run the function above with
|
||||||
|
@ -200,6 +200,18 @@ const a: int = int(1n);
|
|||||||
const b: nat = abs(1);
|
const b: nat = abs(1);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Check if a value is a `nat`
|
||||||
|
|
||||||
|
You can check if a value is a `nat`, by using a syntax specific built-in function, which accepts an `int` and returns an `option(nat)`, more specifically `Some(nat)` if the provided integer is a natural number, and `None` otherwise:
|
||||||
|
|
||||||
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
<!--Pascaligo-->
|
||||||
|
```pascaligo
|
||||||
|
const its_a_nat: option(nat) = is_nat(1)
|
||||||
|
```
|
||||||
|
|
||||||
<!--ReasonLIGO-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo group=e
|
```reasonligo group=e
|
||||||
let a: int = int(1n);
|
let a: int = int(1n);
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
const min_age: nat = 16n;
|
||||||
|
|
||||||
|
function is_adult(const age: nat): bool is
|
||||||
|
if (age > min_age) then True else False
|
@ -0,0 +1 @@
|
|||||||
|
const its_a_nat: option(nat) = is_nat(1)
|
@ -0,0 +1,4 @@
|
|||||||
|
type int_map is map(int, int);
|
||||||
|
function get_first(const int_map: int_map): option(int) is int_map[1]
|
||||||
|
// empty map needs a type annotation
|
||||||
|
const first: option(int) = get_first(((map end) : int_map ));
|
@ -36,6 +36,8 @@ let dog_breed: animal_breed = "Saluki";
|
|||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
> Types in LIGO are `structural`, which means that `animalBreed`/`animal_breed` and `string` are interchangable and are considered equal.
|
||||||
|
|
||||||
## Simple types
|
## Simple types
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
@ -146,3 +148,18 @@ let ledger: account_balances =
|
|||||||
```
|
```
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Annotations
|
||||||
|
|
||||||
|
In certain cases, type of an expression cannot be properly determined. This can be circumvented by annotating an expression with it's desired type, here's an example:
|
||||||
|
|
||||||
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
<!--Pascaligo-->
|
||||||
|
```pascaligo
|
||||||
|
type int_map is map(int, int);
|
||||||
|
function get_first(const int_map: int_map): option(int) is int_map[1]
|
||||||
|
// empty map needs a type annotation
|
||||||
|
const first: option(int) = get_first(((map end) : int_map ));
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
30
gitlab-pages/website/package-lock.json
generated
30
gitlab-pages/website/package-lock.json
generated
@ -5624,15 +5624,6 @@
|
|||||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"klaw-sync": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"graceful-fs": "^4.1.11"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"lazy-cache": {
|
"lazy-cache": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz",
|
||||||
@ -7412,15 +7403,6 @@
|
|||||||
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
|
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"preprocess": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/preprocess/-/preprocess-3.1.0.tgz",
|
|
||||||
"integrity": "sha1-pE5c3Vu7WlTwrSiaru2AmV19k4o=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"xregexp": "3.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"prismjs": {
|
"prismjs": {
|
||||||
"version": "1.17.1",
|
"version": "1.17.1",
|
||||||
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.17.1.tgz",
|
||||||
@ -7750,6 +7732,12 @@
|
|||||||
"picomatch": "^2.0.4"
|
"picomatch": "^2.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"reason-highlightjs": {
|
||||||
|
"version": "0.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/reason-highlightjs/-/reason-highlightjs-0.2.1.tgz",
|
||||||
|
"integrity": "sha512-DWWPtfeQjwKgHj2OOieEIAB544uAVjwOAIAg2Yu09CobdUe41Yah0Z67GEvmVtpYCGG/+3CZvDRM1hMVr1zN3A==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"rechoir": {
|
"rechoir": {
|
||||||
"version": "0.6.2",
|
"version": "0.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
|
||||||
@ -9433,12 +9421,6 @@
|
|||||||
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==",
|
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"xregexp": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-3.1.0.tgz",
|
|
||||||
"integrity": "sha1-FNhGHgvdOCJL/uUDmgiY/EL80zY=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"xtend": {
|
"xtend": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||||
|
Loading…
Reference in New Issue
Block a user