Merge branch 'docs/cameligo-cheat-sheet' into 'dev'
Add CameLIGO cheat sheet to docs Closes LIGO-274 See merge request ligolang/ligo!251
This commit is contained in:
commit
32d53cf9e6
@ -40,6 +40,39 @@ title: Cheat Sheet
|
|||||||
|Transactions|<pre><code>const payment : operation = transaction(unit, amount, receiver);</code></pre>|
|
|Transactions|<pre><code>const payment : operation = transaction(unit, amount, receiver);</code></pre>|
|
||||||
|Exception/Failure|`failwith("Your descriptive error message for the user goes here.")`|
|
|Exception/Failure|`failwith("Your descriptive error message for the user goes here.")`|
|
||||||
|
|
||||||
|
<!--CameLIGO-->
|
||||||
|
|
||||||
|
|Primitive |Example|
|
||||||
|
|--- |---|
|
||||||
|
|Strings | `"Tezos"`|
|
||||||
|
|Characters | `"t"`|
|
||||||
|
|Integers | `42`, `7`|
|
||||||
|
|Natural numbers | `42n`, `7n`|
|
||||||
|
|Unit| `unit`|
|
||||||
|
|Boolean|<pre><code>let has_drivers_license: bool = false<br/>let adult: bool = true</code></pre> |
|
||||||
|
|Boolean Logic|<pre><code>(not true) = false = (false && true) = (false || false)</code></pre>|
|
||||||
|
|Mutez (micro tez)| `42mutez`, `7mutez` |
|
||||||
|
|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`|
|
||||||
|
|Addition |`3 + 4`, `3n + 4n`|
|
||||||
|
|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`|
|
||||||
|
|Modulo| `10 mod 3`|
|
||||||
|
|Tuples| <pre><code>type name = (string * string)<br/>let winner: name = "John", "Doe"<br/>let first_name: string = winner.0<br/>let last_name: string = winner.1</code></pre>|
|
||||||
|
|Types|`type age = int`, `type name = string` |
|
||||||
|
|Includes|```#include "library.mligo"```|
|
||||||
|
|Functions |<pre><code>let add (a : int) (b : int) : int = a + b </code></pre>|
|
||||||
|
| If Statement | <pre><code>let new_id: int = if age < 16 <br/> then failwith("Too young to drive.") <br/> else prev_id + 1</code></pre>|
|
||||||
|
|Options|<pre><code>type middle_name = string option<br/>let middle_name : middle_name = Some "Foo"<br/>let middle_name : middle_name = None</code></pre>|
|
||||||
|
|Variable Binding | ```let age: int = 5```|
|
||||||
|
|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
|
||||||
|
|Variants|<pre><code>type action =<br/>| Increment of int<br/>| Decrement of int</code></pre>|
|
||||||
|
|Variant *(pattern)* matching|<pre><code>let a: action = Increment 5<br/>match a with<br/>| Increment n -> n + 1<br/>| Decrement n -> n - 1<br/></code></pre>|
|
||||||
|
|Records|<pre><code>type person = {<br/> age: int ;<br/> name: string ;<br/>}<br/><br/>let john : person = {<br/> age = 18;<br/> name = "John Doe";<br/>}<br/><br/>let name: string = john.name</code></pre>|
|
||||||
|
|Maps|<pre><code>type prices = (nat, tez) map<br/><br/>let prices : prices = Map.literal [<br/> (10n, 60mutez);<br/> (50n, 30mutez);<br/> (100n, 10mutez)<br/>]<br/><br/>let price: tez option = Map.find 50n prices<br/><br/>let prices: prices = Map.update 200n 5mutez prices</code></pre>|
|
||||||
|
|Contracts & Accounts|<pre><code>let destination_address : address = "tz1..."<br/>let contract : unit contract = <br/> Operation.get_contract destination_address</code></pre>|
|
||||||
|
|Transactions|<pre><code>let payment : operation = <br/> Operation.transaction (unit, receiver, amount)</code></pre>|
|
||||||
|
|Exception/Failure|`failwith("Your descriptive error message for the user goes here.")`|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user