Re: core.logic merge substitutions map?

2013-11-20 Thread Mark
Thanks for the advice and code-snippet.  

On Monday, November 18, 2013 7:43:12 PM UTC-8, Norman Richards wrote:


 On Mon, Nov 18, 2013 at 6:26 PM, Kevin Downey red...@gmail.comjavascript:
  wrote:


 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


 Based on my experience writing pldb, using == in this situation is going 
 to work better than using unify as shown in the code sample base on the 
 video.  I found that using unify for this type of custom relation appears 
 to work but will not do the right thing with more complicated situations. 
  I found constraints particularly problematic.  Switching from unify to == 
 makes sure everything you want to happen on unify actually happens.
  

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: core.logic merge substitutions map?

2013-11-18 Thread Kevin Downey
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=HHZ8iqswiCwexplaining 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?



signature.asc
Description: OpenPGP digital signature


Re: core.logic merge substitutions map?

2013-11-18 Thread Norman Richards
On Mon, Nov 18, 2013 at 6:26 PM, Kevin Downey redc...@gmail.com wrote:


 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


Based on my experience writing pldb, using == in this situation is going to
work better than using unify as shown in the code sample base on the video.
 I found that using unify for this type of custom relation appears to work
but will not do the right thing with more complicated situations.  I found
constraints particularly problematic.  Switching from unify to == makes
sure everything you want to happen on unify actually happens.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


core.logic merge substitutions map?

2013-11-16 Thread Mark
I stumbled across Timothy Baldridge's excellent video 
http://www.youtube.com/watch?v=HHZ8iqswiCwexplaining 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)

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: core.logic merge substitutions map?

2013-11-16 Thread Mark
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=HHZ8iqswiCwexplaining 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)


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.