Imagine I have a number of recipes for different dishes and a larder containing various ingredients in my kitchen. I want to construct a model using core.logic
which will enable me to answer the following question: for a given set of ingredients (i.e. those in my larder now) which recipes can I make?
The recipes are somewhat flexible and I need to be able to model this. Later on I'd like to add quantities to them, but let's leave this out for the moment in order to get started.
I can see how to model the larder:
(db-rel in-larder x)
(def larder (db
[in-larder :carrots]
[in-larder :rice]
[in-larder :garlic]))
The recipes have a name and a list of ingredients which may be optional or combine in various ways. There are n recipes. As an example recipes may look (informally) like this:
Risotto A
=========
(carrots OR peas)
rice
(onions OR garlic)
Risotto B
=========
((carrots AND onions)) OR (rice AND peas))
garlic
I am grappling with how to express this in core.logic
. (N.B. the text above is just illustrative and is not intended to be machine readable.)
I imagine the query would look something like this:
(with-dbs [larder recipes] (run* [q] (possible-recipe q)))
which would return the following result (given the larder definition above):
(:risotto-a :risotto-b)
My question is this: how can I model these recipes so that I can write a query over the recipes and the larder to list the names of the possible recipes given the current contents of my larder?