Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit a list in a given position?
    primarykey
    data
    text
    <p>And it goes like this. Someone have a chain of restaurants. each restaurant is a 3-tuple with a “restaurant name”, an number of tables and a 3-tuple list with the menu (price, "recipe name" , "special ingredient") :</p> <pre><code>("restaurant name", number of tables, [(price, "recipe name" , "special ingredient")]) </code></pre> <p>So, I got something like:</p> <pre><code>chainRestaurants = [("Food and friends",20,[(2.5,"Steak","lemon"),(3.5,"Vegetarian Meals","tomato"),(4.0,"Italian Beef","banana")]),("All in",10,[(2.5,"Stracotto","Garlic"),(3.0,"Roast Beef","Butter"),(3.3,"Veal Chops","Pepper")]),("Orange",25,[(4.5,"Turkey","Mustard"),(5.1,"Chicken","egg"),(6.0,"Chicken Salad","fruit")])] </code></pre> <p>Part of my assignment (the part where I’m stuck in) is: pick the restaurantlist and add, replace, change the order, edit the menus, the restaurants and the restaurant chain list.</p> <p>So, the Question: make a function that allows to edit a 3-tuple (a recipe) from a menu, given the restaurant name position, the menu position and the new recipe.</p> <p>example: editRecipe 1 2 (2222,"SSSSSS","llllll")</p> <p>output:</p> <pre><code>[("Food and friends",20,[(2.5,"Steak","lemon"),(2222,"SSSSSS","llllll"),(4.0,"Italian Beef","banana")]),("All in",10,[(2.5,"Stracotto","Garlic"),(3.0,"Roast Beef","Butter"),(3.3,"Veal Chops","Pepper")]),("Orange",25,[(4.5,"Turkey","Mustard"),(5.1,"Chicken","egg"),(6.0,"Chicken Salad","fruit")])] </code></pre> <p>I've already solve this problem, but never with a 3-tuple as an argument... and I need it! :/</p> <p>There's my code:</p> <pre><code>chainRestaurants = [("Food and friends",20,[(2.5,"Steak","lemon"),(3.5,"Vegetarian Meals","tomato"),(4.0,"Italian Beef","banana")]),("All in",10,[(2.5,"Stracotto","Garlic"),(3.0,"Roast Beef","Butter"),(3.3,"Veal Chops","Pepper")]),("Orange",25,[(4.5,"Turkey","Mustard"),(5.1,"Chicken","egg"),(6.0,"Chicken Salad","fruit")])] menu1 = [(2.5,"Steak","lemon"),(3.5,"Vegetarian Meals","tomato"),(4.0,"Italian Beef","banana")] restaurant1 = ("Food and friends",20,menu1) menu2 = [(2.5,"Stracotto","Garlic"),(3.0,"Roast Beef","Butter"),(3.3,"Veal Chops","Pepper")] restaurant2 = ("All in",10,menu2) menu3 = [(4.5,"Turkey","Mustard"),(5.1,"Chicken","egg"),(6.0,"Chicken Salad","fruit")] restaurant3 = ("Orange",25,menu3) chainRestaurants1 = [restaurant1] ++ [restaurant2] ++ [restaurant3] editRecipe restaurantposition menuposition newrecipe | menuposition == 0 = error "No such thing" | restaurantposition == 1 &amp;&amp; menuposition &gt; length menu1 = error "No such thing" | restaurantposition == 2 &amp;&amp; menuposition &gt; length menu2 = error "No such thing" | restaurantposition == 3 &amp;&amp; menuposition &gt; length menu3 = error "No such thing" editRecipe restaurantposition menuposition newrecipe = case restaurantposition of 1 -&gt; [("Food and friends",20, take (menuposition-1) menu1 ++ newrecipe ++ drop (menuposition) menu1)] ++ [restaurant2] ++ [restaurant3] 2 -&gt; [restaurant1] ++ [("Food and friends",20, take (menuposition-1) menu2 ++ newrecipe ++ drop (menuposition) menu2)] ++ [restaurant3] 3 -&gt; [restaurant1] ++ [restaurant2] ++ [("Orange",25, take (menuposition-1) menu3 ++ newrecipe ++ drop (menuposition) menu3)] otherwise -&gt; error "No such thing" </code></pre> <p>But this code need a list (newrecipe) as argument, but I need a 3-tuple. :/</p> <pre><code>ex: editRecipe 1 2 [(5.1,"xxxxxxxxx","ccccccccccc")] </code></pre> <p>and I need:</p> <pre><code>editRecipe 1 2 (5.1,"xxxxxxxxx","ccccccccccc") </code></pre> <p>But with my code, I must insert a list whit a tuple as argument. The question is: is it possible to insert only a tuple as argument and not a list?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload