From afa0e749e393766a04da937dff12f218fe17ccc7 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 9 Jul 2019 02:29:24 -0700 Subject: [PATCH] Add boolean logic, fail() and if conditional to cheat sheet --- gitlab-pages/docs/language-basics/cheat-sheet.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitlab-pages/docs/language-basics/cheat-sheet.md b/gitlab-pages/docs/language-basics/cheat-sheet.md index 4d8510cfa..58e214dc2 100644 --- a/gitlab-pages/docs/language-basics/cheat-sheet.md +++ b/gitlab-pages/docs/language-basics/cheat-sheet.md @@ -16,6 +16,7 @@ title: Cheat Sheet |Natural numbers | `42n`, `7n`| |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)| `42mtz`, `7mtz` | |Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`| |Addition |`3 + 4`, `3n + 4n`| @@ -26,6 +27,7 @@ title: Cheat Sheet |Includes|```#include "library.ligo"```| |Functions (short form)|
function add (const a : int ; const b : int) : int is
  block { skip } with a + b
| |Functions (long form)|
function add (const a : int ; const b : int) : int is
  block {
    const result: int = a + b;
  } with result
| +| If Statement |
if age < 16 
then fail("Too young to drive.");
else const new_id: int = prev_id + 1;
| |Options|
type middleName is option(string);
const middleName : middleName = Some("Foo");
const middleName : middleName = None;
| |Assignment| ```const age: int = 5;```| |Assignment on an existing variable

*⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` | @@ -36,6 +38,7 @@ title: Cheat Sheet |Maps|
type prices is map(nat, tez);

const prices : prices = map
  10n -> 60mtz;
  50n -> 30mtz;
  100n -> 10mtz;
end

const price: option(tez) = prices[50n];
| |Contracts & Accounts|
const destinationAddress : address = "tz1...";
const contract : contract(unit) = get_contract(destinationAddress);
| |Transactions|
const payment : operation = transaction(unit, amount, receiver);
| +|Exception/Failure|`fail("Your descriptive error message for the user goes here.")`|