ligo/gitlab-pages/docs/reference/toplevel.md

87 lines
1.9 KiB
Markdown
Raw Normal View History

2020-04-01 21:00:39 +04:00
---
id: toplevel
title: Toplevel
description: Available functions at the top level
hide_table_of_contents: true
---
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
These functions are available without any needed prefix.
<SyntaxTitle syntax="pascaligo">
function is_nat: int -> option(nat)
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="cameligo">
2020-04-01 21:00:39 +04:00
val is_nat: int -> nat option
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="reasonligo">
2020-04-01 21:00:39 +04:00
let is_nat: int => option(nat)
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-01 21:00:39 +04:00
Convert an `int` to a `nat` if possible.
<SyntaxTitle syntax="pascaligo">
function abs: int -> nat
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="cameligo">
2020-04-01 21:00:39 +04:00
val abs: int -> nat
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="reasonligo">
2020-04-01 21:00:39 +04:00
let abs: int => nat
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-01 21:00:39 +04:00
Cast an `int` to `nat`.
<SyntaxTitle syntax="pascaligo">
function int: nat -> int
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="cameligo">
2020-04-01 21:00:39 +04:00
val int: nat -> int
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="reasonligo">
2020-04-01 21:00:39 +04:00
let int: nat => int
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-01 21:00:39 +04:00
Cast an `nat` to `int`.
<SyntaxTitle syntax="pascaligo">
const unit: unit
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="cameligo">
2020-04-01 21:00:39 +04:00
val unit: unit
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-03 12:01:35 +04:00
<SyntaxTitle syntax="reasonligo">
2020-04-01 21:00:39 +04:00
let (): unit
2020-04-02 17:14:07 +04:00
</SyntaxTitle>
2020-04-01 21:00:39 +04:00
A helper to create a unit.
<SyntaxTitle syntax="pascaligo">
function failwith : string -> unit
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
2020-04-03 12:01:35 +04:00
val failwith : string -> unit
2020-04-01 21:00:39 +04:00
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-03 12:01:35 +04:00
let failwith : string => unit
2020-04-01 21:00:39 +04:00
</SyntaxTitle>
Cause the contract to fail with an error message.
> ⚠ Using this currently requires in general a type annotation on the
> `failwith` call.
<SyntaxTitle syntax="pascaligo">
function assert : bool -> unit
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
2020-04-03 12:01:35 +04:00
val assert : bool -> unit
2020-04-01 21:00:39 +04:00
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-03 12:01:35 +04:00
let assert : bool => unit
2020-04-01 21:00:39 +04:00
</SyntaxTitle>
Check if a certain condition has been met. If not the contract will fail.