From 77e3b57ff02285dd14f1e1ffc5e7d5bd6900ecd6 Mon Sep 17 00:00:00 2001 From: Micah Kendall Date: Thu, 24 Nov 2022 08:23:46 +1100 Subject: [PATCH] basic docs --- book/src/language-tour/assert.md | 9 ++++++ book/src/language-tour/blocks.md | 35 ++++++++++++++++++++ book/src/language-tour/bool.md | 2 ++ book/src/language-tour/comments.md | 8 +++++ book/src/language-tour/custom-types.md | 45 ++++++++++++++++++++++++++ book/src/language-tour/variables.md | 16 +++++++++ 6 files changed, 115 insertions(+) diff --git a/book/src/language-tour/assert.md b/book/src/language-tour/assert.md index 529924c5..878a2425 100644 --- a/book/src/language-tour/assert.md +++ b/book/src/language-tour/assert.md @@ -1 +1,10 @@ # Assert + +``` +assert rawdata is SomeType +``` + +Causes the script to fail if the rawdata doesn't match the structure of datumtype +Otherwise, returns a value of SomeType + +Primarily for validating input datums / redeemers. \ No newline at end of file diff --git a/book/src/language-tour/blocks.md b/book/src/language-tour/blocks.md index 54e0a5ff..ec5b7c02 100644 --- a/book/src/language-tour/blocks.md +++ b/book/src/language-tour/blocks.md @@ -1 +1,36 @@ # Blocks + +If statements + +``` +if condition { + +} else { + +} +``` + +Case Patterns + +``` +when color is { + Green -> "Success." + Blue -> "Warning." + Red -> "Error!" +} +``` + +Let bindings with blocks + +``` +let num = -5 +let absNum = if num>=0 {num} else {-num} + +let message = when color is { + Green -> "Success." + Blue -> "Warning." + Red -> "Error!" +} +``` + +Since everything is secretly a function, the last statement in any block is implicitly its return. diff --git a/book/src/language-tour/bool.md b/book/src/language-tour/bool.md index d17da479..bd2476fc 100644 --- a/book/src/language-tour/bool.md +++ b/book/src/language-tour/bool.md @@ -1 +1,3 @@ # Bool + +Bools are True or False \ No newline at end of file diff --git a/book/src/language-tour/comments.md b/book/src/language-tour/comments.md index e5799b4c..131c7084 100644 --- a/book/src/language-tour/comments.md +++ b/book/src/language-tour/comments.md @@ -1 +1,9 @@ # Comments + +``` +// Line comments begin with a double-slash + +/// Doc comments begin with a triple-slash + +//// Module comments begin with a quadruple-slash +``` \ No newline at end of file diff --git a/book/src/language-tour/custom-types.md b/book/src/language-tour/custom-types.md index 3a99d7e9..19c002d1 100644 --- a/book/src/language-tour/custom-types.md +++ b/book/src/language-tour/custom-types.md @@ -1 +1,46 @@ # Custom types + + +### Enum Types + +Instantiation + +``` +type Color { + Red + Blue + Green +} + +``` + +Enum types can be thought of as the unit of product types. + +Usage + +``` +fn myFavouriteColor() -> Color { + Red +} +``` + +### Product Types + +``` +type MyValue { + Name(String) + Age(Int) +} +``` + +``` +fn eitherNameOrAge(b: Bool) -> MyValue { + if b { + Name("James") + } else { + Age(20) + } +} +``` + +This example is a bit nonsensical... \ No newline at end of file diff --git a/book/src/language-tour/variables.md b/book/src/language-tour/variables.md index ee1fba42..6df3756c 100644 --- a/book/src/language-tour/variables.md +++ b/book/src/language-tour/variables.md @@ -1 +1,17 @@ # Variables + +Function variables with types +``` +fn add(a:Int, b:Int) -> Int { + a + b +} +``` + +Let bindings +``` +fn something(){ + let a = 3 + let b = 5 + a + b +} +``` \ No newline at end of file