fix "functions.md"
This commit is contained in:
parent
9a5800dc3e
commit
8f4bdcad6a
@ -13,7 +13,7 @@ Each `block` needs to include at least one `instruction`, or a *placeholder* ins
|
|||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
|
|
||||||
```pascaligo
|
```pascaligo skip
|
||||||
// shorthand syntax
|
// shorthand syntax
|
||||||
block { skip }
|
block { skip }
|
||||||
// verbose syntax
|
// verbose syntax
|
||||||
@ -34,7 +34,7 @@ Functions in PascaLIGO are defined using the `function` keyword followed by thei
|
|||||||
Here's how you define a basic function that accepts two `ints` and returns a single `int`:
|
Here's how you define a basic function that accepts two `ints` and returns a single `int`:
|
||||||
|
|
||||||
|
|
||||||
```pascaligo
|
```pascaligo group=a
|
||||||
function add(const a: int; const b: int): int is
|
function add(const a: int; const b: int): int is
|
||||||
begin
|
begin
|
||||||
const result: int = a + b;
|
const result: int = a + b;
|
||||||
@ -51,7 +51,7 @@ The function body consists of two parts:
|
|||||||
Functions that can contain all of their logic into a single instruction/expression, can be defined without the surrounding `block`.
|
Functions that can contain all of their logic into a single instruction/expression, can be defined without the surrounding `block`.
|
||||||
Instead, you can inline the necessary logic directly, like this:
|
Instead, you can inline the necessary logic directly, like this:
|
||||||
|
|
||||||
```pascaligo
|
```pascaligo group=b
|
||||||
function add(const a: int; const b: int): int is a + b
|
function add(const a: int; const b: int): int is a + b
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ along with a return type.
|
|||||||
|
|
||||||
Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
|
Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
|
||||||
|
|
||||||
```cameligo
|
```cameligo group=b
|
||||||
let add (a: int) (b: int) : int = a + b
|
let add (a: int) (b: int) : int = a + b
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ along with a return type.
|
|||||||
|
|
||||||
Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
|
Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
|
||||||
|
|
||||||
```reasonligo
|
```reasonligo group=b
|
||||||
let add = (a: int, b: int) : int => a + b;
|
let add = (a: int, b: int) : int => a + b;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ value.
|
|||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
```pascaligo
|
```pascaligo group=b
|
||||||
const increment : (int -> int) = (function (const i : int) : int is i + 1);
|
const increment : (int -> int) = (function (const i : int) : int is i + 1);
|
||||||
// a = 2
|
// a = 2
|
||||||
const a: int = increment(1);
|
const a: int = increment(1);
|
||||||
@ -104,19 +104,19 @@ Functions without a name, also known as anonymous functions are useful in cases
|
|||||||
Here's how to define an anonymous function assigned to a variable `increment`, with it's appropriate function type signature.
|
Here's how to define an anonymous function assigned to a variable `increment`, with it's appropriate function type signature.
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
<!--Pascaligo-->
|
<!--Pascaligo-->
|
||||||
```pascaligo
|
```pascaligo group=c
|
||||||
const increment : (int -> int) = (function (const i : int) : int is i + 1);
|
const increment : (int -> int) = (function (const i : int) : int is i + 1);
|
||||||
// a = 2
|
// a = 2
|
||||||
const a: int = increment(1);
|
const a: int = increment(1);
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--CameLIGO-->
|
<!--CameLIGO-->
|
||||||
```cameligo
|
```cameligo group=c
|
||||||
let increment : (int -> int) = fun (i: int) -> i + 1
|
let increment : (int -> int) = fun (i: int) -> i + 1
|
||||||
```
|
```
|
||||||
|
|
||||||
<!--ReasonLIGO-->
|
<!--ReasonLIGO-->
|
||||||
```reasonligo
|
```reasonligo group=c
|
||||||
let increment: (int => int) = (i: int) => i + 1;
|
let increment: (int => int) = (i: int) => i + 1;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user