clojure - Expressing that a specific subset of X's have property Y in core.logic -
clojure - Expressing that a specific subset of X's have property Y in core.logic -
i want to:
describe fact subset of class of objects. declare object has property consists of other properties.take next example:
red robotic birds composed of buttons, cheese, , wire.
i want express class of birds, birds reddish , robotic, have property. property composed of buttons, cheese, , wire. there no restrictions on type of wire cheese or buttons. result, should deducible there no reddish robotic birds composed of paper. also, these birds can composed of subset of items buttons, cheese, , wire.
in clojure/core.logic.prelude, there relations , facts using defrel
, fact
. however, can't come combination explain fact.
in prolog there no distinction between facts , goals there in minikanren. might address in future.
btw, i'm not sure answers question - helpful hear types of queries wish run.
this tested code (for clojure 1.3.0-beta1) since i'm using ^:index trick, code run fine in 1.2.0 if swap ^{:index true}:
(ns clojure.core.logic.so (:refer-clojure :exclude [==]) (:use [clojure.core.logic])) (defrel property* ^:index p ^:index t) (fact property* :bird :red-robotic-bird) (fact property* :red :red-robotic-bird) (fact property* :robotic :red-robotic-bird) (fact property* :tasty :cake) (fact property* :red-robotic-bird :macaw) (defn property [p t] (conde [(property* p t)] [(fresh [ps] (property* ps t) (property p ps))])) (defrel composition* ^:index m ^:index t) (fact composition* :buttons :red-robotic-bird) (fact composition* :cheese :red-robotic-bird) (fact composition* :wire :red-robotic-bird) (fact composition* :flour :cake) (defn composition [m t] (fresh [p] (composition* m p) (conde [(== p t)] [(property p t)])))
trying out.
(comment ;; macaw composed of? (run* [q] (composition q :macaw)) ;; (:wire :cheese :buttons) ;; things include buttons in composition? (run* [q] (composition :buttons q)) ;; (:red-robotic-bird :macaw) ;; macaw include flour in composition? (run* [q] (composition :flour :macaw)) ;; () ;; macaw bird? (run* [q] (property :bird :macaw)) ;; (_.0) ;; cake bird? (run* [q] (property :bird :cake)) ;; () ;; properties of macaw? (run* [q] (property q :macaw)) ;; (:red-robotic-bird :robotic :bird :red) )
clojure clojure-core.logic
Comments
Post a Comment