________________________________________________________________________

This file is part of Logtalk <http://logtalk.org/>  

Logtalk is free software. You can redistribute it and/or modify it under
the terms of the FSF GNU General Public License 3  (plus some additional
terms per section 7).        Consult the `LICENSE.txt` file for details.
________________________________________________________________________


% start by loading the example:

| ?- logtalk_load(recipes(loader)).
yes


% list all the ingredients required for the green soup recipe:

| ?- green_soup::ingredients(Ingredients).
Ingredients = [peas,cream,water,oil]
yes


% list all the steps required to make mashed peas:

| ?- mashed_peas::steps(Steps).
Steps = [1-'Boil the peas.',2-'Mash the peas',3-'Add salt and mix.']
yes


% find out what dishes you can cook with green peas:

| ?- conforms_to_protocol(Recipe, recipep), Recipe::ingredient(peas).
Recipe = green_soup ? ;
Recipe = mashed_peas ? ;
no


% patch the prototypical recipe to add a level/1 descriptor to all recipes:

| ?- logtalk_load(recipes(patch_1)).
yes

% you always get into trouble while making green soup:

| ?- green_soup::assertz(level(hard)).
yes


% but most recipes are easy; add a second patch to define a default value
% for the level/1 descriptor to all recipes that don't specify a different
% level and check it:

| ?- logtalk_load(recipes(patch_1)).
yes

| ?- mashed_peas::level(Level).
Level = easy
yes


% when using a mixed representation, the conforms_to_protocol/2 built-in
% predicate is not ideal to enumerate recipes as it will also return the
% parametric object used for accessing recipes represented as Prolog facts:

| ?- conforms_to_protocol(Recipe, recipep).
Recipe = green_soup ;
Recipe = mashed_peas ;
Recipe = recipe(_, _, _) ;
no

% thus, to enumerate recipes, is best to use the recipe/1 predicate, which
% ensures that we always get a proper recipe:

Recipe = green_soup ;
Recipe = mashed_peas ;
Recipe = recipe('Chocolate Chip Cookies', [flour-500-gr, butter-20-gr, chocolate-200-gr, sugar-65-gr, eggs-2-units], ['mix flour, butter and sugar'-10-min, 'add eggs and mix'-10-min, 'make chocolate chips'-5-min, 'split in small portions'-5-min, 'cook in the oven'-25-min]) ;
Recipe = recipe('Berries and cream', [cream-500-ml, sugar-50-gr, strawberries-300-gr, chocolate-100-gr], ['mix whipping cream add sugar'-5-min, 'slice strawberries'-5-min, 'place alternate layers of cream and strawberries in dessert dishes'-10-min, 'make chocolate chips'-5-min, 'top dishes with chocolate chips'-5-min]) ;
no

% an usage example of the recipe/1 predicate would be:

?- recipe(Recipe), Recipe::cooking_time(CookingTime).
Recipe = green_soup,
CookingTime = 36 ;
Recipe = mashed_peas,
CookingTime = 16 ;
Recipe = recipe('Chocolate Chip Cookies', [flour-500-gr, butter-20-gr, chocolate-200-gr, sugar-65-gr, eggs-2-units], ['mix flour, butter and sugar'-10-min, 'add eggs and mix'-10-min, 'make chocolate chips'-5-min, 'split in small portions'-5-min, 'cook in the oven'-25-min]),
CookingTime = 55 ;
Recipe = recipe('Berries and cream', [cream-500-ml, sugar-50-gr, strawberries-300-gr, chocolate-100-gr], ['mix whipping cream add sugar'-5-min, 'slice strawberries'-5-min, 'place alternate layers of cream and strawberries in dessert dishes'-10-min, 'make chocolate chips'-5-min, 'top dishes with chocolate chips'-5-min]),
CookingTime = 30 ;
no
