From 156db3c4c05acf8a0c1f8034d80f0fc57875aa06 Mon Sep 17 00:00:00 2001 From: Frank Hillard Date: Tue, 13 Oct 2020 14:25:29 +0200 Subject: [PATCH] rework instructions --- .../Chapters/Camel/ChapterInterop/course.md | 20 ++++++++++++++++++- .../Chapters/Pascal/ChapterInterop/course.md | 19 +++++++++++++++++- .../Chapters/Reason/ChapterInterop/course.md | 20 ++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/pages/Chapters/Camel/ChapterInterop/course.md b/src/frontend/src/pages/Chapters/Camel/ChapterInterop/course.md index 57a584a..40af6f7 100644 --- a/src/frontend/src/pages/Chapters/Camel/ChapterInterop/course.md +++ b/src/frontend/src/pages/Chapters/Camel/ChapterInterop/course.md @@ -289,4 +289,22 @@ let make_abstract_record (z: string) (y: int) (x: string) (w: bool) (v: int) : t We want you to modify our "inventory" contract. As you can see the storage is mainly composed of an item inventory where each item is a right combed nested pair. The contract possesses a single entry point AddInventory. This _AddInventory_ function adds each element in the inventory (don't worry about duplicates it has already been taken care of). -1- Complete the implementation of the *update\_inventory* lambda function. This function takes a list of items as parameter and must transform each item in a combed pair structure and add this resulting structure in the storage inventory. (When naming your temporary variables, use *acc* for the accumulator name and *i* for the current item) +1- Complete the implementation of the *update\_inventory* lambda function. This function must transform each item in a combed pair structure. + +Take a look at the instruction using the *update\_inventory* lambda function : + +``` +let new_inventory : item_michelson list = List.fold update_inventory item_list s.inventory in +(([] : operation list), {s with inventory=new_inventory}) +``` + +As you can see the *update\_inventory* lambda function is applied to the given list of items and the resulting structure updates the storage inventory. + +(Recall) As you can see the *update\_inventory* lambda function is used in a *List.fold* instruction which implies that the *update\_inventory* lambda function takes 2 parameters : +- an accumulator (conventionnaly named *acc*) +- an item of the given folded list +and produces a new accumulator. + +When naming your parameters, use *acc* for the accumulator name and *i* for the current item. + +(Recall) One can use the *::* operator to add an element in a list. \ No newline at end of file diff --git a/src/frontend/src/pages/Chapters/Pascal/ChapterInterop/course.md b/src/frontend/src/pages/Chapters/Pascal/ChapterInterop/course.md index a679aae..8c2c666 100644 --- a/src/frontend/src/pages/Chapters/Pascal/ChapterInterop/course.md +++ b/src/frontend/src/pages/Chapters/Pascal/ChapterInterop/course.md @@ -321,4 +321,21 @@ function make_abstract_record (const z: string; const y: int; const x: string; c We want you to modify our "inventory" contract. As you can see the storage is mainly composed of an item inventory where each item is a right combed nested pair. The contract possesses a single entry point AddInventory. This _AddInventory_ function adds each element in the inventory (don't worry about duplicates it has already been taken care of). -1- Complete the implementation of the *update_inventory* lambda function. This function takes a list of items as parameter and must transform each item in a combed pair structure and add this resulting structure in the storage inventory. (When naming your temporary variables, use *acc* for the accumulator name and *i* for the current item) +1- Complete the implementation of the *update\_inventory* lambda function. This function must transform each item in a combed pair structure. + +Take a look at the instruction using the *update\_inventory* lambda function : + +``` +s.inventory := List.fold(update_inventory, item_list, s.inventory); +``` + +As you can see the *update\_inventory* lambda function is applied to the given list of items and the resulting structure updates the storage inventory. + +(Recall) As you can see the *update\_inventory* lambda function is used in a *List.fold* instruction which implies that the *update\_inventory* lambda function takes 2 parameters : +- an accumulator (conventionnaly named *acc*) +- an item of the given folded list +and produces a new accumulator. + +When naming your parameters, use *acc* for the accumulator name and *i* for the current item. + +(Recall) One can use the *#* operator to add an element in a list. diff --git a/src/frontend/src/pages/Chapters/Reason/ChapterInterop/course.md b/src/frontend/src/pages/Chapters/Reason/ChapterInterop/course.md index 9943bda..abdfc72 100644 --- a/src/frontend/src/pages/Chapters/Reason/ChapterInterop/course.md +++ b/src/frontend/src/pages/Chapters/Reason/ChapterInterop/course.md @@ -301,4 +301,22 @@ let make_abstract_record = (z: string, y: int, x: string, w: bool, v: int) : tes We want you to modify our "inventory" contract. As you can see the storage is mainly composed of an item inventory where each item is a right combed nested pair. The contract possesses a single entry point AddInventory. This _AddInventory_ function adds each element in the inventory (don't worry about duplicates it has already been taken care of). -1- Complete the implementation of the *update_inventory* lambda function. This function takes a list of items as parameter and must transform each item in a combed pair structure and add this resulting structure in the storage inventory. (When naming your temporary variables, use *acc* for the accumulator name and *i* for the current item) +1- Complete the implementation of the *update\_inventory* lambda function. This function must transform each item in a combed pair structure. + +Take a look at the instruction using the *update\_inventory* lambda function : + +``` + let new_inventory : list(item_michelson) = List.fold(update_inventory, item_list, s.inventory); + (([] : list(operation)), {...s, inventory:new_inventory}) +``` + +As you can see the *update\_inventory* lambda function is applied to the given list of items and the resulting structure updates the storage inventory. + +(Recall) As you can see the *update\_inventory* lambda function is used in a *List.fold* instruction which implies that the *update\_inventory* lambda function takes 2 parameters : +- an accumulator (conventionnaly named *acc*) +- an item of the given folded list +and produces a new accumulator. + +When naming your parameters, use *acc* for the accumulator name and *i* for the current item. + +(Recall) One can use the *[element, ...list]* pattern to add an element in a list. \ No newline at end of file