From 12ceeb5d8676705474e82a278786e4ef09a3c3f6 Mon Sep 17 00:00:00 2001 From: Aymeric Bethencourt Date: Wed, 22 Apr 2020 17:12:36 +0200 Subject: [PATCH] refactor chapter 10 to 16 --- .env | 1 + public/fonts/vulcan.ttf | Bin 0 -> 28484 bytes src/Chapter/Chapter.controller.tsx | 40 ++++---- src/Chapters/ChapterAddresses/course.md | 34 +++---- src/Chapters/ChapterAddresses/exercise.ligo | 31 +----- src/Chapters/ChapterAddresses/solution.ligo | 33 +------ src/Chapters/ChapterBuiltIns/course.md | 91 +++++------------ src/Chapters/ChapterBuiltIns/exercise.ligo | 7 +- src/Chapters/ChapterBuiltIns/solution.ligo | 9 +- src/Chapters/ChapterCast/course.md | 93 ------------------ src/Chapters/ChapterCast/exercise.ligo | 5 - src/Chapters/ChapterCast/index.ts | 11 --- src/Chapters/ChapterCast/solution.ligo | 7 -- src/Chapters/ChapterFailwith/course.md | 22 ----- src/Chapters/ChapterFailwith/exercise.ligo | 5 - src/Chapters/ChapterFailwith/index.ts | 11 --- src/Chapters/ChapterFailwith/solution.ligo | 6 -- src/Chapters/ChapterFunctions/course.md | 2 +- src/Chapters/ChapterInclusions/course.md | 3 - src/Chapters/ChapterInclusions/exercise.ligo | 20 ---- src/Chapters/ChapterInclusions/index.ts | 11 --- src/Chapters/ChapterInclusions/solution.ligo | 22 ----- src/Chapters/ChapterLists/course.md | 6 +- src/Chapters/ChapterLists/solution.ligo | 2 +- src/Chapters/ChapterLoops/course.md | 14 ++- src/Chapters/ChapterLoops/exercise.ligo | 58 ++++++++--- src/Chapters/ChapterLoops/solution.ligo | 65 +++++++++--- src/Chapters/ChapterMainFunction/course.md | 73 +++++++++----- .../ChapterMainFunction/exercise.ligo | 24 ++++- .../ChapterMainFunction/solution.ligo | 28 +++++- src/Chapters/ChapterMaps/course.md | 4 +- src/Chapters/ChapterMaps/solution.ligo | 2 +- src/Chapters/ChapterMath/course.md | 13 +-- src/Chapters/ChapterMath/solution.ligo | 2 +- src/Chapters/ChapterRecords/course.md | 2 +- src/Chapters/ChapterStrings/course.md | 2 +- src/Chapters/ChapterTuples/course.md | 2 +- src/Chapters/ChapterTypes/course.md | 2 +- src/Chapters/ChapterVariables/course.md | 2 +- src/Chapters/ChapterVariant/course.md | 89 ++++++++--------- src/Chapters/ChapterVariant/exercise.ligo | 42 +------- src/Chapters/ChapterVariant/solution.ligo | 46 +-------- src/Drawer/Drawer.view.tsx | 18 ++-- 43 files changed, 355 insertions(+), 605 deletions(-) create mode 100644 .env create mode 100644 public/fonts/vulcan.ttf delete mode 100644 src/Chapters/ChapterCast/course.md delete mode 100644 src/Chapters/ChapterCast/exercise.ligo delete mode 100644 src/Chapters/ChapterCast/index.ts delete mode 100644 src/Chapters/ChapterCast/solution.ligo delete mode 100644 src/Chapters/ChapterFailwith/course.md delete mode 100644 src/Chapters/ChapterFailwith/exercise.ligo delete mode 100644 src/Chapters/ChapterFailwith/index.ts delete mode 100644 src/Chapters/ChapterFailwith/solution.ligo delete mode 100644 src/Chapters/ChapterInclusions/course.md delete mode 100644 src/Chapters/ChapterInclusions/exercise.ligo delete mode 100644 src/Chapters/ChapterInclusions/index.ts delete mode 100644 src/Chapters/ChapterInclusions/solution.ligo diff --git a/.env b/.env new file mode 100644 index 0000000..2d2e9a0 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +INLINE_RUNTIME_CHUNK=false \ No newline at end of file diff --git a/public/fonts/vulcan.ttf b/public/fonts/vulcan.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e999e555863951a3ace309328f23c3241e341be2 GIT binary patch literal 28484 zcmd7537i~PeJB22-S^p5)pu8Szv`Zzp6Q-_FLLeAt!(t%(fe^@_cy~#%5N89s$&zHV|38}#pIvs74?))cURBTG zST?>0J2O>NRqws3SMUAa?|R?gD})h31{y#tdTPh+_RxjTzV&K^Zuucx-G0-FgQt5w z_MhL6(9It}2!HRU^XJ0MquDDV{WzrGd-U|pCq8i9_dbdc|A%mX_~zqx9{r1t)!&Vf z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!&grpNB#ktRKZdFO{MF4gf;?o=cbDY6xiU1JIJm+0wl+%Q)G90>q{|cRC z{sc|n|A00zfIWpT8Et(-p81!s`uQt-Ci5lcBJ)>Fj`<*S7ycNtnHj|U@K0DB$oJcq z_M?$Ye|zcPOJBTn^3ubw`j?9SJ>Chid&gn@-X@HWlb1e*VWh)XoGwBS8K5DVuuj;c zFsi>cPA^olljOP&D1AX_0&|@L`1nohf6NEalA|imnaqtNi0ah&(If3ILm>eKk zu=KVF7dcqd_vI2*_(({cg$EoLEf1M_z}Z7&INX9BsZjo<6EztLf(mQHLRlUbVWQs^ z;3X&_39yA1tFI!}>7-90@ut|AIugyqpLty^3`4 zeNlji!g5U#fCdFcfKB8T2qy(w_+=AK70Md|l$U`iDR5`F1C)pF13-EB=z(ayC=o6% zCtAP)BvX(icsBi}0hEW8J4M)FO)J3VijwuRiM9^qEs>T7o~Q}%SpxV6A5YL^L6hJ} zvR{-4mzNVA1Ie;2$}&6~mZ5^jLV5VY0DNLV&;ji$$^Ps)_+MgExR>#$-bk4F!&r)XOG%7L<>(z!xhN zQ_>VwmQ7h!Oo~-hpu9)RzaSAlaj~4}+elSCS%sB3U=cD4UK?s)DGIES1nZV5CahHS zvWbBMo=RW*nqxfucb?w4`V@l-CtlQw=s9qTAp| q%e*KNfS*f=>8uOo(~w1_ { const [validatorState, setValidatorState] = useState(PENDING); @@ -63,26 +61,30 @@ export const Chapter = () => { setData({ course: dataLists.course, exercise: dataLists.exercise, solution: dataLists.solution }); if (pathname === "/12") setData({ - course: dataMainFunction.course, - exercise: dataMainFunction.exercise, - solution: dataMainFunction.solution, + course: dataVariant.course, + exercise: dataVariant.exercise, + solution: dataVariant.solution, }); if (pathname === "/13") setData({ - course: dataTimestamps.course, - exercise: dataTimestamps.exercise, - solution: dataTimestamps.solution, + course: dataMainFunction.course, + exercise: dataMainFunction.exercise, + solution: dataMainFunction.solution, }); if (pathname === "/14") - setData({ course: dataBuiltIns.course, exercise: dataBuiltIns.exercise, solution: dataBuiltIns.solution }); + setData({ course: dataLoops.course, exercise: dataLoops.exercise, solution: dataLoops.solution }); if (pathname === "/15") - setData({ course: dataCast.course, exercise: dataCast.exercise, solution: dataCast.solution }); + setData({ course: dataAddresses.course, exercise: dataAddresses.exercise, solution: dataAddresses.solution }); if (pathname === "/16") - setData({ course: dataTuples.course, exercise: dataTuples.exercise, solution: dataTuples.solution }); + setData({ course: dataBuiltIns.course, exercise: dataBuiltIns.exercise, solution: dataBuiltIns.solution }); if (pathname === "/17") - setData({ course: dataFailWith.course, exercise: dataFailWith.exercise, solution: dataFailWith.solution }); + setData({ + course: dataTransactions.course, + exercise: dataTransactions.exercise, + solution: dataTransactions.solution, + }); if (pathname === "/18") - setData({ course: dataVariant.course, exercise: dataVariant.exercise, solution: dataVariant.solution }); + setData({ course: dataTimestamps.course, exercise: dataTimestamps.exercise, solution: dataTimestamps.solution }); if (pathname === "/19") setData({ course: dataPatternMatching.course, diff --git a/src/Chapters/ChapterAddresses/course.md b/src/Chapters/ChapterAddresses/course.md index 003798f..4457e2f 100644 --- a/src/Chapters/ChapterAddresses/course.md +++ b/src/Chapters/ChapterAddresses/course.md @@ -1,36 +1,30 @@ -# Chapter 12 : Addresses +# Chapter 15 : Addresses -## Addresses +The scan showed some unusual activity on the planet Osiris, it's likely we will find Xenomorph activity there. We should gear up first. I suggest we stop by a weapon merchant. Here is the address. -You can define Tezos addresses by casting a string to an address type : +## Casting + +You can cast a type into another type if you are sure they are compatible : ``` -const my_account : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) +const a : int = int (1n) +const b : nat = abs (-3) ``` -⚠️ You will not see a transpilation error if the address you enter is wrong but the execution will fail. +⚠️ You will not see a transpilation error if the types are not compatible but the execution will fail. -## Signatures +## Addresses -You can also cast strings as Tezos signatures (edsig, spsig) : +You can define Tezos addresses by casting a string to an address type : ``` -const my_sig : signature = ("edsigthTzJ8X7MPmNeEwybRAvdxS1pupqcM5Mk4uCuyZAe7uEk68YpuGDeViW8wSXMrCi5CwoNgqs8V2w8ayB5dMJzrYCHhD8C7" : signature) +const my_account : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) ``` -## Keys - -Same principle for Tezos public keys : - -``` -const my_key : key = ("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" : key) -``` +⚠️ You will not see a transpilation error if the address you enter is wrong but the execution will fail. ## Your mission - -1- Modify the mapping *owner\_of* so that the owner is no longer a string but an address. - -2- Make the Galactica belong to address "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" +1- Define *ship\_address* as _tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV_ -3- Make the Enterprise belong to address "tz1YfuHeaaPyKFGAjrCskb8kzEEkmaMhiDhd" +2- Define *vendor\_address* as _tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx_ diff --git a/src/Chapters/ChapterAddresses/exercise.ligo b/src/Chapters/ChapterAddresses/exercise.ligo index 0dcf877..1b7e7f7 100644 --- a/src/Chapters/ChapterAddresses/exercise.ligo +++ b/src/Chapters/ChapterAddresses/exercise.ligo @@ -1,29 +1,4 @@ -type ship is - record [ - name : string; - code : string; - price : tez; - created_at : timestamp - ] - -// Type your solution below -type owner is map (string, string) - -function main (const p : unit; const store : owner) : (list(operation) * owner) is - block { - const my_ship : ship = - record [ - name = "Galactica"; - code = "222031"; - price = 1tez; - created_at = Tezos.now - ]; - +function purchase (const purchase_price : tez) : bool is // Type your solution below - const owner_of : owner = - map [ - "Galactica" -> "Adama"; - "Enterprise" -> "Kirk"; - ]; - store := owner_of; - } with ((nil: list(operation)), store) \ No newline at end of file + +return True \ No newline at end of file diff --git a/src/Chapters/ChapterAddresses/solution.ligo b/src/Chapters/ChapterAddresses/solution.ligo index b9ef743..19df8f2 100644 --- a/src/Chapters/ChapterAddresses/solution.ligo +++ b/src/Chapters/ChapterAddresses/solution.ligo @@ -1,29 +1,6 @@ -type ship is - record [ - name : string; - code : string; - price : tez; - created_at : timestamp - ] - -// Type your solution below -type owner is map (string, address) - -function main (const p : unit; const store : owner) : (list(operation) * owner) is - block { - const my_ship : ship = - record [ - name = "Galactica"; - code = "222031"; - price = 1tez; - created_at = Tezos.now - ]; - +function purchase (const purchase_price : tez) : bool is // Type your solution below - const owner_of : owner = - map [ - "Galactica" -> ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); - "Enterprise" -> ("tz1YfuHeaaPyKFGAjrCskb8kzEEkmaMhiDhd" : address); - ]; - store := owner_of; - } with ((nil: list(operation)), store) \ No newline at end of file + const ship_address : address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); + const vendor_address : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); + +return True \ No newline at end of file diff --git a/src/Chapters/ChapterBuiltIns/course.md b/src/Chapters/ChapterBuiltIns/course.md index a0f857d..b678ddf 100644 --- a/src/Chapters/ChapterBuiltIns/course.md +++ b/src/Chapters/ChapterBuiltIns/course.md @@ -1,88 +1,49 @@ -# Chapter 14 : Built-ins +# Chapter 16 : Built-ins -A LIGO smart contract can query part of the state of the Tezos blockchain by means of built-in values. In this section you will find how those built-ins can be utilized. - -## Accepting or Declining Tokens in a Smart Contract - -This example shows how Tezos.amount and failwith can be used to decline any transaction that sends more tez than 0tez, that is, no incoming tokens are accepted. - -``` -type parameter is unit -type storage is unit -type return is list (operation) \* storage - -function deny (const action : parameter; const store : storage) : return is -if Tezos.amount > 0tez then -(failwith ("This contract does not accept tokens.") : return) -else ((nil : list (operation)), store) -``` +We need a Flux Capacitor, don't ask me why, you wouldn't get it. Just buy it! -Note that amount is deprecated. Please use Tezos.amount. - -## Access Control - -This example shows how Tezos.source can be used to deny access to an entrypoint. +A LIGO smart contract can query part of the state of the Tezos blockchain by means of built-in values. In this section you will find how those built-ins can be utilized. -``` -const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); +## A few built-ins -function main (const action : parameter; const store : storage) : return is -if Tezos.source =/= owner then (failwith ("Access denied.") : return) -else ((nil : list (operation)), store) -``` +_Tezos.balance_ : Get the balance for the contract. -Note that source is deprecated. Please use Tezos.source. +_Tezos.amount_ : Get the amount of tez provided by the sender to complete this transaction. -## Inter-Contract Invocations +_Tezos.sender_ : Get the address that initiated the current transaction. -It would be somewhat misleading to speak of "contract calls", as this wording may wrongly suggest an analogy between contract "calls" and function "calls". Indeed, the control flow returns to the site of a function call, and composed function calls therefore are stacked, that is, they follow a last in, first out ordering. This is not what happens when a contract invokes another: the invocation is queued, that is, follows a first in, first our ordering, and the dequeuing only starts at the normal end of a contract (no failure). That is why we speak of "contract invocations" instead of "calls". +*Tezos.self\_address* : Get the address of the currently running contract. -The following example shows how a contract can invoke another by emiting a transaction operation at the end of an entrypoint. +_Tezos.source_ : Get the originator (address) of the current transaction. That is, if a chain of transactions led to the current execution get the address that began the chain. Not to be confused with Tezos.sender, which gives the address of the contract or user which directly caused the current transaction. -The same technique can be used to transfer tokens to an implicit account (tz1, ...): all you have to do is use a unit value as the parameter of the smart contract. +*Tezos.chain\_id* : Get the identifier of the chain to distinguish between main and test chains. -In our case, we have a counter.ligo contract that accepts an action of type parameter, and we have a proxy.ligo contract that accepts the same parameter type, and forwards the call to the deployed counter contract. +ℹ️ A more complete list is available on ligolang.org -``` -// counter.ligo -type parameter is -Increment of nat -| Decrement of nat -| Reset +## Failwith -type storage is unit +The keyword _failwith_ throws an exception and stop the execution of the smart contract -type return is list (operation) \* storage ``` - +failwith() ``` -// proxy.ligo - -type parameter is -Increment of nat -| Decrement of nat -| Reset -type storage is unit - -type return is list (operation) \* storage +## Access Control -const dest : address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3" : address) +This example shows how Tezos.source can be used to deny access to an entrypoint. -function proxy (const action : parameter; const store : storage): return is -block { -const counter : contract (parameter) = -case (Tezos.get*contract_opt (dest) : option (contract (parameter))) of -Some (contract) -> contract -| None -> (failwith ("Contract not found.") : contract (parameter)) -end; +``` +const owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); -const mock_param : parameter = Increment (5n); -const op : operation = Tezos.transaction (action, 0tez, counter); -const ops : list (operation) = list [op] -} with (ops, store) +function main (const action : parameter; const store : storage) : return is + if Tezos.source =/= owner then (failwith ("Access denied.") : return) +else ((nil : list (operation)), store) ``` +__ must be a string value + ## Your mission -Coming soon ... +1- Check that the originitor address is indeed our *ship\_address*, or fail with _"Access denied"_ + +2- Check that the sent amount corresponds to the *purchase\_price*, or fail with _"Incorrect amount"_ diff --git a/src/Chapters/ChapterBuiltIns/exercise.ligo b/src/Chapters/ChapterBuiltIns/exercise.ligo index c35cae8..edb5e0c 100644 --- a/src/Chapters/ChapterBuiltIns/exercise.ligo +++ b/src/Chapters/ChapterBuiltIns/exercise.ligo @@ -1,2 +1,7 @@ -// Type your solution below +function purchase (const purchase_price : tez) : bool is + const ship_address : address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); + const vendor_address : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); + // Type your solution below + +return True \ No newline at end of file diff --git a/src/Chapters/ChapterBuiltIns/solution.ligo b/src/Chapters/ChapterBuiltIns/solution.ligo index c35cae8..05210ef 100644 --- a/src/Chapters/ChapterBuiltIns/solution.ligo +++ b/src/Chapters/ChapterBuiltIns/solution.ligo @@ -1,2 +1,9 @@ -// Type your solution below +function purchase (const purchase_price : tez) : bool is + const ship_address : address = ("tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" : address); + const vendor_address : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); + // Type your solution below + if Tezos.source =/= ship_address then failwith ("Access denied") + if Tezos.amount =/= purchase_price then failwith ("Incorrect amount") + +return True \ No newline at end of file diff --git a/src/Chapters/ChapterCast/course.md b/src/Chapters/ChapterCast/course.md deleted file mode 100644 index 9c24075..0000000 --- a/src/Chapters/ChapterCast/course.md +++ /dev/null @@ -1,93 +0,0 @@ -# Chapter 4 : Math - -LIGO offers three built-in numerical types: - -- _int_ are integers, such as 10, -6 and 0. - -- _nat_ are natural numbers (integral numbers greater than or equal to zero). They are follwed by the suffix _n_ such as 3n, 12n and 0n for the natural zero. - -- _tez_ are units of measure of Tezos tokens. They can be decinmals and are followed by _tez_ or _tz_ such as 3tz or 12.4tez. You can also type units of millionth of tez, using the suffix _mutez_ after a natural literal, such as 10000mutez or 0mutez. - -⚠️ Notice there are no floating point types in LIGO as they are not determinist in hardware modules. - - -ℹ️Large integral values can be expressed using underscores to separate groups of digits, like 1\_000mutez or 0.000\_004tez. Notice 1tez = 1\_000\_000mutez. - -## Addition - -Addition in LIGO is accomplished by means of the + infix operator. Some type constraints apply, for example you cannot add a value of type tez to a value of type nat. - -``` -const a : int = 5 + 10 -const b : int = 5n + 10 -const c : tez = 5mutez + 0.000_010tez -``` - -⚠️ You cannot add a tez and a int. - -## Substraction - -Substractions follow the same principles. - -``` -const a : int = 5 - 10 -const b : int = 5n - 2n -const d : tez = 5mutez - 1mutez -``` - -## Multiplication - -Multiplications follow the same principles. - -``` -const a : int = 5 * 5 -const b : nat = 5n * 5n -const c : tez = 5n * 5mutez -``` - -## Division - -Divisions follow the same principles. - -``` -const a : int = 10 / 3 -const b : nat = 10n / 3n -const c : nat = 10mutez / 3mutez -``` - -## Modulo - -Modulos follow the same principles. - -``` -const a : int = 120 -const b : int = 9 -const rem1 : nat = a mod b // 3 -``` - -## From int to nat and back - -You can cast an int to a nat and vice versa. Here is how: - -``` -const a: int = int(1n) -const b: nat = abs(1) -``` - -## Checking a nat - - -*is\_nat* returns a _nat_ or _None_ - -``` -const is_a_nat : option (nat) = is_nat (1) -``` - -## Your mission - -You received a laserbeam message from Interstellar Academy: "Today's lesson: space combat simulation - Know your opponent ! How strong is he ?". - - -An armoured battleship _ship1_ is attacking a weaker battleship _ship2_. A third ship (_ship3_) is coming to rescue _ship2_ in order to have an even fight ! -1- In the editor, compute _ship3_ armor (which is the difference of armor between _ship1_ and _ship2_) in a constant variable *diff\_armor* -2- In the editor, assign previously computed _ship3_ armor to variable *ship3\_armor* diff --git a/src/Chapters/ChapterCast/exercise.ligo b/src/Chapters/ChapterCast/exercise.ligo deleted file mode 100644 index b6b6b5e..0000000 --- a/src/Chapters/ChapterCast/exercise.ligo +++ /dev/null @@ -1,5 +0,0 @@ -type ship_armor is nat -var ship1_armor : ship_armor := 10n; -var ship2_armor : ship_armor := 5n; -var ship3_armor : ship_armor := 0n; -// Type your solution below diff --git a/src/Chapters/ChapterCast/index.ts b/src/Chapters/ChapterCast/index.ts deleted file mode 100644 index 6243b3d..0000000 --- a/src/Chapters/ChapterCast/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import exercise from "!raw-loader!./exercise.ligo"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import solution from "!raw-loader!./solution.ligo"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import course from "!raw-loader!./course.md"; - -export const dataCast = { course, exercise, solution }; diff --git a/src/Chapters/ChapterCast/solution.ligo b/src/Chapters/ChapterCast/solution.ligo deleted file mode 100644 index c388dab..0000000 --- a/src/Chapters/ChapterCast/solution.ligo +++ /dev/null @@ -1,7 +0,0 @@ -type ship_armor is nat -var ship1_armor : ship_armor := 10n; -var ship2_armor : ship_armor := 5n; -var ship3_armor : ship_armor := 0n; -// Type your solution below -const diff_armor : int = ship1_armor - ship2_armor; -var ship3_armor : ship_armor := abs(diff_armor); diff --git a/src/Chapters/ChapterFailwith/course.md b/src/Chapters/ChapterFailwith/course.md deleted file mode 100644 index 6b95ddf..0000000 --- a/src/Chapters/ChapterFailwith/course.md +++ /dev/null @@ -1,22 +0,0 @@ -# Chapter 17 : Failwith - -## Description - -The keyword _failwith_ throws an exception and stop the execution of the smart contract - -## Syntax - -The _failwith_ instruction follows the syntax : - -``` -failwith() -``` - -__ must be a string value - -# Your mission - -Due to the increasing number of spaceship registration the Interstellar Government is upgrading its Space Registration smart contract. All transactions are stopped for the moment. - - -1- In the Editor, stop the program execution by throwing an exception with message "Not implemented" diff --git a/src/Chapters/ChapterFailwith/exercise.ligo b/src/Chapters/ChapterFailwith/exercise.ligo deleted file mode 100644 index bc12da8..0000000 --- a/src/Chapters/ChapterFailwith/exercise.ligo +++ /dev/null @@ -1,5 +0,0 @@ -function main (const p : unit; const store : unit) : (list(operation) * unit) is - block { - // Type your solution below - - } with ((nil: list(operation)), unit) \ No newline at end of file diff --git a/src/Chapters/ChapterFailwith/index.ts b/src/Chapters/ChapterFailwith/index.ts deleted file mode 100644 index 6fb4af2..0000000 --- a/src/Chapters/ChapterFailwith/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import course from "!raw-loader!./course.md"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import exercise from "!raw-loader!./exercise.ligo"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import solution from "!raw-loader!./solution.ligo"; - -export const dataFailWith = { course, exercise, solution }; diff --git a/src/Chapters/ChapterFailwith/solution.ligo b/src/Chapters/ChapterFailwith/solution.ligo deleted file mode 100644 index f412dfd..0000000 --- a/src/Chapters/ChapterFailwith/solution.ligo +++ /dev/null @@ -1,6 +0,0 @@ -function main (const p : unit; const store : unit) : (list(operation) * unit) is - block { - // Type your solution below - failwith("Not implemented") - - } with ((nil: list(operation)), unit) \ No newline at end of file diff --git a/src/Chapters/ChapterFunctions/course.md b/src/Chapters/ChapterFunctions/course.md index 23c67dc..2390d91 100644 --- a/src/Chapters/ChapterFunctions/course.md +++ b/src/Chapters/ChapterFunctions/course.md @@ -1,6 +1,6 @@ # Chapter 6 : Functions -Hey, why are you trying to change the part yourself? Just write a function on the terminal and send it to a droid. +Captain, why are you trying to change the part yourself? Just write a function on the terminal and send it to a droid. LIGO functions are the basic building block of contracts. Each entrypoint of a contract is a function and each smart contract must have at least one function named _main_ that dispatches controls to the other functions. diff --git a/src/Chapters/ChapterInclusions/course.md b/src/Chapters/ChapterInclusions/course.md deleted file mode 100644 index 5355ada..0000000 --- a/src/Chapters/ChapterInclusions/course.md +++ /dev/null @@ -1,3 +0,0 @@ -# Chapter 15 : Inclusions - -Coming soon... diff --git a/src/Chapters/ChapterInclusions/exercise.ligo b/src/Chapters/ChapterInclusions/exercise.ligo deleted file mode 100644 index 6082c91..0000000 --- a/src/Chapters/ChapterInclusions/exercise.ligo +++ /dev/null @@ -1,20 +0,0 @@ -// Type your solution below -type ship is - record [ - name : string; - code : string; - price : tez - ] - -const my_ship : ship = - record [ - name : "Galactica"; - code : "222031"; - price : 1tez - ] - -type owner is map (string, address) -const owner_of : owner = - map [ - ("Galactica" : "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx") - ] diff --git a/src/Chapters/ChapterInclusions/index.ts b/src/Chapters/ChapterInclusions/index.ts deleted file mode 100644 index ea39778..0000000 --- a/src/Chapters/ChapterInclusions/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import course from "!raw-loader!./course.md"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import exercise from "!raw-loader!./exercise.ligo"; -/* eslint import/no-webpack-loader-syntax: off */ -// @ts-ignore -import solution from "!raw-loader!./solution.ligo"; - -export const dataInclusions = { course, exercise, solution }; diff --git a/src/Chapters/ChapterInclusions/solution.ligo b/src/Chapters/ChapterInclusions/solution.ligo deleted file mode 100644 index 9bd6ae5..0000000 --- a/src/Chapters/ChapterInclusions/solution.ligo +++ /dev/null @@ -1,22 +0,0 @@ -// Type your solution below -type ship is - record [ - name : string; - code : string; - price : tez; - created_at : timestamp - ] - -const my_ship : ship = - record [ - name : "Galactica"; - code : "222031"; - price : 1tez; - created_at : Tezos.now - ] - -type owner is map (string, address) -const owner_of : owner = - map [ - ("Galactica" : "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx") - ] diff --git a/src/Chapters/ChapterLists/course.md b/src/Chapters/ChapterLists/course.md index 5a31f15..90dda65 100644 --- a/src/Chapters/ChapterLists/course.md +++ b/src/Chapters/ChapterLists/course.md @@ -1,6 +1,6 @@ # Chapter 11 : Lists and Sets -You should now plot our course. +Please now plot our course as a list of destinations. Lists are linear collections of elements of the same type. Linear means that, in order to reach an element in a list, we must visit all the elements before (sequential access). Elements can be repeated, as only their order in the collection matters. The first element is called the head, and the sub-list after the head is called the tail. @@ -12,6 +12,8 @@ To define an empty list : const empty_list : list (int) = list [] ``` +ℹ️ You can also use _nil_ instead of list [] + To define list with values: ``` @@ -58,4 +60,4 @@ const smaller_set : set (int) = Set.remove (3, my_set) 2- On the next line, add _"sun"_ to the itinary. -2- On the next line, add _"alpha-centory"_ to the itinary. +2- On the next line, add _"alpha-centauri"_ to the itinary. diff --git a/src/Chapters/ChapterLists/solution.ligo b/src/Chapters/ChapterLists/solution.ligo index 071392d..ad5e5c6 100644 --- a/src/Chapters/ChapterLists/solution.ligo +++ b/src/Chapters/ChapterLists/solution.ligo @@ -1,4 +1,4 @@ // Type your solution below var itinary : list (string) := list ["earth"] itinary : list (string) = "sun" # itinary -itinary : list (string) = "alpha-centory" # itinary +itinary : list (string) = "alpha-centauri" # itinary diff --git a/src/Chapters/ChapterLoops/course.md b/src/Chapters/ChapterLoops/course.md index 66c4249..9afd32f 100644 --- a/src/Chapters/ChapterLoops/course.md +++ b/src/Chapters/ChapterLoops/course.md @@ -1,4 +1,6 @@ -# Chapter 8 : Loops +# Chapter 14 : Loops + +Captain, now that we left the atmosphere of earth, we should scan nearby star systems for alien activity. We know that the Xenomorphs like planets with high density, usually above 100 g/cm³ and that their machines trigger atmospheric activity. You should trigger a scan with these parameters. LIGO integrate 2 kinds of loops. General while iterations and bounded for loops. @@ -33,6 +35,8 @@ for i := 1 to 10 block { } ``` +## Iterations + For-loops can also iterate through the contents of a collection, that is, a list, a set or a map. This is done with : ``` @@ -52,6 +56,12 @@ function sum_list (var l : list (int)) : int is block { } with total ``` +Same from sets with _for i in set s_ and maps with _for key -> value in map m_ + ## Your mission -Modify the contract so that the function iterates over all attributes of the ship and changes all occurences of "2" by "1". +1- Check the proposed code in the editor. Notice that we created a star map as a list of planet records. + +2- Notice the unimplemented scan function. Suppose this function is called from the main function with the *star\_map* variable as its input _l_. Code a for loop that iterates through each record of the list. + +3- Inside the loop, code a conditional for *density* supperior to 100 and *atmospheric\_activity* true. If so, assign *destination* to its *name*. diff --git a/src/Chapters/ChapterLoops/exercise.ligo b/src/Chapters/ChapterLoops/exercise.ligo index a43406e..cc9cb15 100644 --- a/src/Chapters/ChapterLoops/exercise.ligo +++ b/src/Chapters/ChapterLoops/exercise.ligo @@ -1,13 +1,47 @@ -type ship_code is string -var my_ship : ship_code := "020433" -my_ship := "222031" -const my_ship_price : tez = 3tez * 1.20 +type coordinates is (nat * nat * nat) +type planet is + record [ + name : string; + position : coordinates; + density : nat; + atmospheric_activity : bool + ] -function modify_ship (const my_ship : ship_code) : ship_code is - block { - // Type your solution below - var modified_ship : ship_code := my_ship; - if String.sub(2n, 1n, my_ship) = "0" then - modified_ship := String.sub(0n, 2n, my_ship) ^ "1" ^ String.sub(3n, 3n, my_ship) - else skip; - } with modified_ship \ No newline at end of file +var star_map : list (planet) := list [ + record [ + name = "Earth"; + position = (0,0,0); + density = 20; + atmospheric_activity = True + ]; + record [ + name = "Jupiter"; + position = (2,7,1); + density = 340; + atmospheric_activity = False + ]; + record [ + name = "Methuselah"; + position = (2232,7423,12342); + density = 44; + atmospheric_activity = False + ]; + record [ + name = "Osiris"; + position = (134,454,1321); + density = 165; + atmospheric_activity = True + ]; + record [ + name = "Gliese"; + position = (234,8045,435); + density = 11; + atmospheric_activity = True + ]; +] + +function scan (var l : list (planet)) : planet is block { + var destination : planet; + // Type your solution below + +} with destination \ No newline at end of file diff --git a/src/Chapters/ChapterLoops/solution.ligo b/src/Chapters/ChapterLoops/solution.ligo index 033e633..75f300d 100644 --- a/src/Chapters/ChapterLoops/solution.ligo +++ b/src/Chapters/ChapterLoops/solution.ligo @@ -1,17 +1,50 @@ -type ship_code is string -var my_ship : ship_code := "020433" -my_ship := "222031" -const my_ship_price : tez = 3tez * 1.20 +type coordinates is (nat * nat * nat) +type planet is + record [ + name : string; + position : coordinates; + density : nat; + atmospheric_activity : bool + ] -function modify_ship (const my_ship : ship_code) : ship_code is - block { - var modified_ship : ship_code := my_ship; - // Type your solution below - var i : nat := 0n; - while i < 5n block { - if String.sub(i, 1n, my_ship) = "2" then - modified_ship := String.sub(0n, i, my_ship) ^ "1" ^ String.sub(i + 2n, 5n - i, my_ship) - else skip; - i := i + 1n - } - } with modified_ship \ No newline at end of file +var star_map : list (planet) := list [ + record [ + name = "Earth"; + position = (0,0,0); + density = 20; + atmospheric_activity = True + ]; + record [ + name = "Jupiter"; + position = (2,7,1); + density = 340; + atmospheric_activity = False + ]; + record [ + name = "Methuselah"; + position = (2232,7423,12342); + density = 44; + atmospheric_activity = False + ]; + record [ + name = "Osiris"; + position = (134,454,1321); + density = 165; + atmospheric_activity = True + ]; + record [ + name = "Gliese"; + position = (234,8045,435); + density = 11; + atmospheric_activity = True + ]; +] + +function scan (var l : list (planet)) : planet is block { + var destination : planet; + // Type your solution below + for i in list l block { + if i.density > 100 and i.atmospheric_activity then destination = i.name + else skip; + } +} with destination \ No newline at end of file diff --git a/src/Chapters/ChapterMainFunction/course.md b/src/Chapters/ChapterMainFunction/course.md index b98e7a8..a8a6db2 100644 --- a/src/Chapters/ChapterMainFunction/course.md +++ b/src/Chapters/ChapterMainFunction/course.md @@ -1,32 +1,19 @@ -# Chapter 8 : Main function +# Chapter 13 : Main function God damn it rookie! What are you still doing at the space port? Take off already and go shoot some alien!! -A LIGO contract is made of a series of constants and function declarations. Only functions having a special type can be called when the contract is activated: we call them _main_ functions. A main function takes two parameters, the _contract parameter_ and the _on-chain storage_, and returns a pair made of a _list of operations_ and a _(new) storage_. +A LIGO contract is made of a series of constant and function declarations. Only functions having a special type can be called when the contract is activated: we call them main functions. A main function takes two parameters, the contract parameter and the on-chain storage, and returns a pair made of a list of operations and a (new) storage. When the contract is originated, the initial value of the storage is provided. When a main function is later called, only the parameter is provided, but the type of a main function contains both. -The type of the contract parameter and the storage are up to the contract designer, but the type for list operations is not. The return type of a main function is as follows, assuming that the type _storage_ has been defined elsewhere. (Note that you can use any type with any name for the storage.) - -The contract storage can only be modified by activating a main function: given the state of the storage on-chain, a main function specifies how to create another state for it, depending on the contract's parameter. - -## Syntax - -The Main function of a smart contract follows syntax definition of regular function but must have a specific prototype. - -1- The Main function must contain exactly 2 parameters (one is the contract parameter, and the other is the storage) - -2- The Main function return a tuple (list(operation) \* ) where is the storage type definition +The type of the contract parameter and the storage are up to the contract designer, but the type for list operations is not. The return type of a main function is as follows, assuming that the type storage has been defined elsewhere. (Note that you can use any type with any name for the storage.) ``` -function (const :; const :) : (list(operation) * ) is -block { } -with (, ) +type storage is ... // Any name, any type +type return is list (operation) * storage ``` -Note that most of the time the main fonction return an empty list of operations and the new state of the storage - -## Exemple +The contract storage can only be modified by activating a main function: given the state of the storage on-chain, a main function specifies how to create another state for it, depending on the contract's parameter. Here is an example where the storage is a single natural number that is updated by the parameter. @@ -39,13 +26,49 @@ function save (const action : parameter; const store : storage) : return is ((nil : list (operation)), store) ``` -# Your mission +## Entrypoints + +In LIGO, the design pattern is to have one main function called main, that dispatches the control flow according to its parameter. Those functions called for those actions are called entrypoints. + +As an analogy, in the C programming language, the main function is the unique main function and any function called from it would be an entrypoint. + +The parameter of the contract is then a variant type, and, depending on the constructors of that type, different functions in the contract are called. In other terms, the unique main function dispatches the control flow depending on a pattern matching on the contract parameter. + +In the following example, the storage contains a counter of type nat and a name of type string. Depending on the parameter of the contract, either the counter or the name is updated. + +``` +type Action is + Action_A of string +| Action_B of string + +type Storage is record [ + stored_string_A : string; + stored_string_B : string +] + +type return is list (operation) * storage + +function entry_A (const input_string : string; const storage : Storage) : return is + ((nil : list (operation)), storage with record [stored_string_A = input_string]) + +function entry_B (const input_string : string; const storage : Storage) : return is + ((nil : list (operation)), storage with record [stored_string_B = input_string]) + +function main (const action : Action; const storage : Storage): return is + case action of + Action_A (input_string) -> entry_A (input_string, storage) + | Action_B (input_string) -> entry_B (input_string, storage) + end +``` + +ℹ️ Now that you created a main function, you can now transpile your code into Michaelson and deploy it on Tezos. Try it out on the LIGOlang IDE + +## Your mission - -1- Define the _on-line storage_ type named *storage* which stores a single string +1- The editor contains an example of main function with two functions. In the Action variant, replace *Action\_A* and *Action\_B* with our actions *Set\_ship\_code* and *Go\_to* -2- Create a Main function called _main_ which takes a first parameter named _p_ of type string and storage state as second parameter named _store_ +2- In the Storage record, replace *stored\_string\_A* and *stored\_string\_B* with the strings we want to store in the contract: *ship\_code* and *destination* -3- The body of the Main function must do nothing +3- Modify the name of our entrypoints *entry\_A* and *entry\_B* to *set\_ship\_code* and *go\_to* -4- The return of the Main function will assign the value of _p_ as the new storage state +4- Modify the main function to reflect the new names above diff --git a/src/Chapters/ChapterMainFunction/exercise.ligo b/src/Chapters/ChapterMainFunction/exercise.ligo index 3788732..8dc9bbf 100644 --- a/src/Chapters/ChapterMainFunction/exercise.ligo +++ b/src/Chapters/ChapterMainFunction/exercise.ligo @@ -1 +1,23 @@ -// Type your solution below +// Modify the code below +type action is + Action_A of string +| Action_B of string + +type storage is record [ + stored_string_A : string; + stored_string_B : string +] + +type return is list (operation) * storage + +function entry_A (const input_string : string; const store : storage) : return is + ((nil : list (operation)), store with record [stored_string_A = input_string]) + +function entry_B (const input_string : string; const store : storage) : return is + ((nil : list (operation)), store with record [stored_string_B = input_string]) + +function main (const input_action : action; const store : storage): return is + case input_action of + Action_A (input_string) -> entry_A (input_string, store) + | Action_B (input_string) -> entry_B (input_string, store) + end diff --git a/src/Chapters/ChapterMainFunction/solution.ligo b/src/Chapters/ChapterMainFunction/solution.ligo index 46ba8fe..16597ed 100644 --- a/src/Chapters/ChapterMainFunction/solution.ligo +++ b/src/Chapters/ChapterMainFunction/solution.ligo @@ -1,5 +1,23 @@ -// Type your solution below -type storage is string -function main (const p : string; const store : storage) : (list(operation) * storage) is - block { skip } - with ((nil: list(operation)), p) \ No newline at end of file +// Modify the code below +type action is + Set_ship_code of string +| Go_to of string + +type storage is record [ + ship_code : string; + destination : string +] + +type return is list (operation) * storage + +function set_ship_code (const input_string : string; const store : storage) : return is + ((nil : list (operation)), store with record [ship_code = input_string]) + +function go_to (const input_string : string; const store : storage) : return is + ((nil : list (operation)), store with record [destination = input_string]) + +function main (const input_action : action; const store : storage): return is + case input_action of + Set_ship_code (input_string) -> set_ship_code (input_string, store) + | Go_to (input_string) -> go_to (input_string, store) + end diff --git a/src/Chapters/ChapterMaps/course.md b/src/Chapters/ChapterMaps/course.md index d61f785..1457f45 100644 --- a/src/Chapters/ChapterMaps/course.md +++ b/src/Chapters/ChapterMaps/course.md @@ -1,6 +1,6 @@ # Chapter 10 : Maps -Ok it's time to open our star map and decide where we want to go. +Ok it's now time to open our star map and decide where we want to go. Maps are a data structure which associate values of the same type to values of the same type. The former are called key and the latter values. Together they make up a binding. An additional requirement is that the type of the keys must be comparable, in the Michelson sense. @@ -74,4 +74,4 @@ remove "tim" from map user_balances 2- Define the type *name\_to\_coordinates* as a mapping from the celestial body name to its coordinates. -3- Add values for _earth_ at 2,7,1 , the _sun_ at 0,0,0 and _alpha-centory_ at 2232,7423,12342 . +3- Add values for _earth_ at 2,7,1 , the _sun_ at 0,0,0 and _alpha-centauri_ at 2232,7423,12342 . diff --git a/src/Chapters/ChapterMaps/solution.ligo b/src/Chapters/ChapterMaps/solution.ligo index 30816d5..c83a216 100644 --- a/src/Chapters/ChapterMaps/solution.ligo +++ b/src/Chapters/ChapterMaps/solution.ligo @@ -5,5 +5,5 @@ const star_map : planet_to_coordinates = map [ "earth" -> (2,7,1); "sun" -> (0,0,0); - "alpha-centory" -> (2232,7423,12342) + "alpha-centauri" -> (2232,7423,12342) ] diff --git a/src/Chapters/ChapterMath/course.md b/src/Chapters/ChapterMath/course.md index e5c31cd..8236077 100644 --- a/src/Chapters/ChapterMath/course.md +++ b/src/Chapters/ChapterMath/course.md @@ -1,6 +1,6 @@ # Chapter 4 : Math -Hello rookie, I'm Dr Zod, I hope you didn't sleep during your Math class in the academy because you're gonna need it! Your ship needs at least 1.21 gigawatts to function properly. Battery packs are 0.16 gigawatts per unit. How many battery packs do you need? Seems easy, right? Well, no, because the system doesn't run floating point numbers, so... good luck with that! +Hello, I'm Dr Zod, I hope you didn't sleep during your Math class in the academy because you're gonna need it! Your ship needs at least 1.21 gigawatts to function properly. Battery packs are 0.16 gigawatts per unit. How many battery packs do you need? Seems easy, right? Well, no, because the system doesn't run floating point numbers, so... good luck with that! LIGO offers three built-in numerical types: @@ -69,15 +69,6 @@ const b : int = 9 const rem1 : nat = a mod b // 3 ``` -## From int to nat and back - -You can cast an int to a nat and vice versa using the _int_ or _abs_ functions. Here is how: - -``` -const a: int = int(1n) -const b: nat = abs(1) -``` - ## Checking a nat @@ -93,4 +84,4 @@ const is_a_nat : option (nat) = is_nat (1) 2- Define *energy\_per\_battery\_pack* for 0.16 gigawatts. -3- Define and compute *required\_battery\_packs* as the number of battery packs required to power your ship. +3- Define and compute *required\_battery\_packs* as the number of battery packs required to power your ship. Remember that floating point numbers are truncated to an integer, e.g. 10 / 3 = 3 in LIGO and not 3.33333333.... diff --git a/src/Chapters/ChapterMath/solution.ligo b/src/Chapters/ChapterMath/solution.ligo index 863147b..69fb1c7 100644 --- a/src/Chapters/ChapterMath/solution.ligo +++ b/src/Chapters/ChapterMath/solution.ligo @@ -1,4 +1,4 @@ // Type your solution below const required_energy : int = 1210; -const energy_per_battery_pack : int = 500; +const energy_per_battery_pack : int = 160; const required_battery_packs : int = required_energy / energy_per_battery_pack + 1 \ No newline at end of file diff --git a/src/Chapters/ChapterRecords/course.md b/src/Chapters/ChapterRecords/course.md index d5981e4..8080007 100644 --- a/src/Chapters/ChapterRecords/course.md +++ b/src/Chapters/ChapterRecords/course.md @@ -1,6 +1,6 @@ # Chapter 9 : Records -Thanks for the coordinates but I'm not sure I understand which value correspond to wich component. You may want to be more explicit. +Thanks for the coordinates captain but I'm not sure I understand which value corresponds to which coordinate. You mean x,y,z ? You may want to be more explicit. Records are like tuples but with named parameters. In other words, they hold a set of key/data pairs. To instanciate a record, you must first declare its type as follow : diff --git a/src/Chapters/ChapterStrings/course.md b/src/Chapters/ChapterStrings/course.md index a51d508..d9ade59 100644 --- a/src/Chapters/ChapterStrings/course.md +++ b/src/Chapters/ChapterStrings/course.md @@ -1,6 +1,6 @@ # Chapter 5 : Strings -When you powered the ship, the engines exploded... Seems like someone sabotaged it! We'll find out later. For now, you need to replace the part. +Red alert captain! When you powered the ship, the engines exploded... Seems like someone sabotaged the igniter! We should find out later. For now, you need to replace the damaged part. Strings are defined using the built-in string type as follows: diff --git a/src/Chapters/ChapterTuples/course.md b/src/Chapters/ChapterTuples/course.md index a4524fa..c818c02 100644 --- a/src/Chapters/ChapterTuples/course.md +++ b/src/Chapters/ChapterTuples/course.md @@ -1,6 +1,6 @@ # Chapter 8 : Tuples -Hey, I'm James, the pilot of this piece of junk. Just let me know the coordinates of where you want to go and I'll try my best to bring us there in one piece... +Hey captain, I'm lieutenant Washburne, the pilot of this piece of junk. Just let me know the coordinates of where you want to go and I'll try my best to bring us there in one piece... Tuples gather multiple values in a specific order which can be retrieved with their indexes. diff --git a/src/Chapters/ChapterTypes/course.md b/src/Chapters/ChapterTypes/course.md index bd39e5d..fa95e7d 100644 --- a/src/Chapters/ChapterTypes/course.md +++ b/src/Chapters/ChapterTypes/course.md @@ -1,6 +1,6 @@ # Chapter 2 : Types -Welcome onboard, I'm the ship's mechanics. The first thing to do before departing is to define your ship's paramaters. Go ahead! +Welcome onboard captain, I'm the ship's mechanics. The first thing to do before departing is to define your ship's paramaters. Go ahead! LIGO is strongly and statically typed language. This means that the compiler checks how your contract processes data. If it passes the test, your contract will not fail at run-time due to inconsistent assumptions on your data. This is called type checking. diff --git a/src/Chapters/ChapterVariables/course.md b/src/Chapters/ChapterVariables/course.md index 9e40117..d1dcb20 100644 --- a/src/Chapters/ChapterVariables/course.md +++ b/src/Chapters/ChapterVariables/course.md @@ -1,6 +1,6 @@ # Chapter 3 : Variables -You're not very good, are you? Seems like you have locked the parameters. You should unlock them so we can later change the ship configuration if need be. +Seems like you have locked-in the parameters. You should unlock them so we can later change the ship configuration if need be. ## Constants diff --git a/src/Chapters/ChapterVariant/course.md b/src/Chapters/ChapterVariant/course.md index 6a6505b..988766b 100644 --- a/src/Chapters/ChapterVariant/course.md +++ b/src/Chapters/ChapterVariant/course.md @@ -1,85 +1,76 @@ -# Chapter 18 : Variants +# Chapter 12 : Unit, Variant, Option and Pattern matching -## Description +Captain, before we go, you may want to setup your commands to set the ship code and go to a destination. -A variant type is a user-defined or a built-in type (in case of options) that defines a type by cases, so a value of a variant type is either this, or that or... The simplest variant type is equivalent to the enumerated types found in Java, C++, JavaScript. +Optionals are a pervasive programing pattern in OCaml. Since Michelson and LIGO are both inspired by OCaml, optional types are available in LIGO as well. Similarly, OCaml features a unit type, and LIGO features it as well. Both the option type and the unit types are instances of a more general kind of types: variant types (sometimes called sum types). -The "|" keyword allow to create variants. A variant is a user-defined type which can accept exclusively different types. The "|" operator can be understood as a "or" between types. +## Unit -For example, here is how we define a coin as being either head or tail - -``` -type coin is Head | Tail -``` +The unit type in Michelson or LIGO is a predefined type that contains only one value that carries no information. It is used when no relevant information is required or produced. Here is how it used. -And here is how a variable (of variant type _coin_) is initialized with one of the two possible values. +In PascaLIGO, the unique value of the unit type is Unit. ``` -const head : coin = Head -const tail : coin = Tail +const n : unit = Unit // Note the capital letter ``` -Notice that all possibles values for a variant are capitalized (_Head_, _Tail_) - -In this particular, possibles values (_Head_, _Tail_) carry no information beyond their names, so they are called constant constructors, but variants can carry some information. +## Variant -## Syntax +A variant type is a user-defined or a built-in type (in case of options) that defines a type by cases, so a value of a variant type is either this, or that or... The simplest variant type is equivalent to the enumerated types found in Java, C++, JavaScript etc. -The variant definition follows the syntax : +Here is how we define a coin as being either head or tail (and nothing else): ``` -type is -| of -| of +type Coin is Head | Tail +const head : Coin = Head +const tail : Coin = Tail ``` -Types definitions () refers to primitive type (nat, int,..) or predefined type such as unit or any other user custom types. +The names Head and Tail in the definition of the type coin are called data constructors, or variants. In this particular, they carry no information beyond their names, so they are called constant constructors. -### unit +In general, it is interesting for variants to carry some information, and thus go beyond enumerated types. In the following, we show how to define different kinds of users of a system. -The unit type in Michelson or LIGO is a predefined type that contains only one value that carries no information. It is used when no relevant information is required or produced. Here is how it used. +``` +type Id is nat -In PascaLIGO, the unique value of the unit type is Unit. +type User is +Admin of Id +| Manager of Id +| Guest -``` -const n : unit = Unit +const user : User = Admin (1000n) +const guest : User = Guest ``` -(notice the capital letter for the value) +In LIGO, a constant constructor is equivalent to the same constructor taking an argument of type unit, so, for example, Guest is the same value as Guest (unit). -## Assignement +## Option -A variable can be define for a variant type , it follows the syntax: +The option type is a predefined variant type that is used to express whether there is a value of some type or none. This is especially useful when calling a partial function, that is, a function that is not defined for some inputs. In that case, the value of the option type would be None, otherwise Some (v), where v is some meaningful value of any type. An example in arithmetic is the division operation: ``` -const : =