https://github.com/sonian/Greenmail/blob/master/src/clj/greenmail/db.clj#L98-L126
has an example, using clojure.core.logic/all to make a goal which is a
conjunction of the clojure.core.logic/== goals

On 11/16/13, 5:04 PM, Mark wrote:
> d'oh!  Answering my own question:  Just compose the unify functions a la 
> (unify (unify a v1 (:v1 r) v2 (:v2 r))
> 
> I have a feeling there is a library function/macro that would make this 
> less messy but I can't find it from the cheatsheet.
> 
> On Saturday, November 16, 2013 10:31:50 AM UTC-8, Mark wrote:
>>
>> I stumbled across Timothy Baldridge's excellent video 
>> <http://www.youtube.com/watch?v=HHZ8iqswiCw>explaining how to incorporate 
>> data sources into core.logic.  It reinvigorated my interest in using 
>> core.logic to query SQL RDBMS.  I'm stumbling on a pretty simple thing, I 
>> think.  I've got a table that has three columns, a single primary key 
>> column and two value columns.  Using the pattern Tim outlines in his video, 
>> I've got a relation function that takes three parameters, one for each 
>> column and I'm trying to work through the case where the primary key is 
>> ground and the value columns are lvars.  This translates to a query of the 
>> form SELECT v1, v2 FROM t WHERE pkey=?.  Of course, this returns two values 
>> that must be unified.  That's where I'm stuck.
>>
>> I know I want to return a substitution map, but I have two lvars to 
>> unify.  How do I merge the two substitution maps?
>>
>> Sample code:
>> (defn pkey-v1-v2-o [pkey v1 v2]
>>   (fn [a]
>>     (let [pkey (walk a pkey)
>>           v1 (walk a v1)
>>           v2(walk a v2)]
>>       (condp = [(not (lvar? pkey))
>>                 (not (lvar? v1))
>>                 (not (lvar? v2))]
>>         [true false false ] (to-stream 
>>                               (let [r (first (query ["SELECT v1, v2 FROM T 
>> WHERE pkey=?" pkey]))]
>>                                 (some-merge-fn (unify a v1 (:v1 r))
>>                                                (unify a v2 (:v2 r)))))))))
>>
> 


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to