Hi,

I'm trying to use featurec to describe some relationships within a nested 
map. When I try to use it to find some keys in the map it returns nothing. 
Here is an example:

;; Here is a map of some foods
> (def foods {:apple {:color "Red"}
>             :carrot {:color "Orange"}
>             :tomato {:color "Red"}
>             :celery {:color "Green"}}) 


> ;; What is the :color of :apple?
> ;; This works -- it returns ("Red")
> (run* [q]
>       (featurec foods {:apple {:color q}})) 


> ;; Show me every food that has the :color "Red" 

;; I expect to get back (:apple :tomato)

;; This doesn't work -- it returns ()
> (run* [q]
>       (featurec foods {q {:color "Red"}})) 


> ;; Give me the name of a key for :apple that has the value "Red" 

;; This should return (:color)

;; This doesn't work -- it returns ()
> (run* [q]
>       (featurec foods {:apple {q "Red"}}))



I realize there is a good chance I am trying to ask featurec to do 
something it isn't designed for. Is this true? If so, what is a better way?

One solution I have come up with is to massage the map into a vector like 
this:

;; The foods as maps within a vector and the names as values instead of keys
> (def vector-of-foods [{:name "Apple" :color "Red"}
>                       {:name "Carrot" :color "Orange"}
>                       {:name "Tomato" :color "Red"}
>                       {:name "Celery" :color "Green"}]) 


> ;; What foods are :color "Red" ?
> ;; This works -- it returns ("Apple" "Tomato")
> (run* [q]
>       (fresh [f]
>              (membero f vector-of-foods)
>              (featurec f {:color "Red"})
>              (featurec f {:name q})))


I would do this if the data I was dealing with was just the colors of food, 
but what I am really trying to do is use core.logic to create programs that 
understand relationships in AWS 
CloudFormation<http://aws.amazon.com/cloudformation/> templates. 
A CFN template is a JSON file that is a bunch of nested maps that describe 
cloud computing infrastructure. I feel there are risks to massaging the 
templates and featurec feels right. What am I missing? Any guidance is 
appreciated.

Thanks,
Dave

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to