<< Back to previous view

[LOGIC-138] Allow tying multiple noms in one binder Created: 10/Jun/13  Updated: 10/Jun/13

Status: Open
Project: core.logic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Tom Jack Assignee: David Nolen
Resolution: Unresolved Votes: 0
Labels: nominal


 Description   

I think it may be useful to be able to tie multiple noms in one binder, with or without significant order.

A couple use cases I've thought of so far:

Lambdas in a non-currying language. Here order matters.

(== (list 'fn (ties [x y] (list '+ x y)))
    (list 'fn (ties [z w] (list '+ z w)))

My original use case, free/quantified variables in logical formulas. Order doesn't matter (note the second body has its noms swapped).

(== (list '∀ (ties #{x y} (list '= (list '+ x y) (list '+ y x))))
    (list '∀ (ties #{z w} (list '= (list '+ w z) (list '+ z w)))))

I have a draft implementation here: https://github.com/tomjack/core.logic/compare/ties

Possible issues with this implementation:

  • Is it OK to reextend IWalkTerm to IPersistentSet?
  • Should Tie and Ties present a uniform interface? (e.g. (tie? (ties #{x} x)))


 Comments   
Comment by David Nolen [ 10/Jun/13 3:37 PM ]

I really don't think the set bit is necessary, the vector syntax is fine. Also avoid needing to bring IWalkTerm back for sets. And yes, tie? should work in either case.

Comment by Tom Jack [ 10/Jun/13 3:55 PM ]

Hmm.. should:

(== (list 'fn (ties [x y] (list '- x y)))
    (list 'fn (ties [z w] (list '- w z)))

I'd think not.

Do you mean that order should always matter (take out the permutations stuff), or that it should never matter (don't use ties for cases like the above)?

Comment by David Nolen [ 10/Jun/13 4:07 PM ]

Ah hm, good point. Will think on it some more.





[LOGIC-127] Swapping noms turns maps (and other collections) into seqs Created: 02/Apr/13  Updated: 28/Jul/13  Resolved: 10/Apr/13

Status: Closed
Project: core.logic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Jiří Maršík Assignee: Nada Amin
Resolution: Completed Votes: 0
Labels: bug, nominal

Attachments: Text File INomSwap-vectors-maps.patch     Text File INomSwap-vectors-maps-with-test.patch    
Approval: Accepted

 Description   

When I unify two binders, the swapping procedure turns all the maps inside the body into seqs of key/value pairs, which do not unify with maps, leading to the following trickiness:

(require '[clojure.core.logic :as l])
(require '[clojure.core.logic.nominal :as n])
(l/run* [q]
  (l/fresh [body]
    (n/fresh [a b]
      (l/== (n/tie a {:k a}) (n/tie b body))
      (l/== {:k q} body))))
;=> ()
; Expected (a_0)

For my purposes, fixing this by adding two new implementations of INomSwap for vectors and maps works well.



 Comments   
Comment by Jiří Maršík [ 02/Apr/13 11:14 AM ]

Oops, sorry for the malformatted code snippet. Here it is inside a code tag.

(require '[clojure.core.logic :as l])
(require '[clojure.core.logic.nominal :as n])
(l/run* [q]
        (l/fresh [body]
                 (n/fresh [a b]
                          (l/== (n/tie a {:k a}) (n/tie b body))
                          (l/== {:k q} body))))
;=> ()
; Expected (a_0)
Comment by David Nolen [ 02/Apr/13 11:22 AM ]

This seems like a easy one to fix, perhaps Nada can see quicker than I can. If not I can take a look.

Also your patch may very well solve the issue best, feel free to attach it to the ticket. We won't be able to apply it until you've submitted your Contributor Agreement - if you have a free moment please send it in. Thanks!

Comment by Jiří Maršík [ 02/Apr/13 11:48 AM ]

The patch that I use to fix the issue. I haven't signed the CA, but I would definitely like to. Might take a while to arrive though, since I'm in Europe and I'm lazy.

Comment by Nada Amin [ 03/Apr/13 2:36 AM ]

The patch LGTM. I would also add a test from the ticket example.

I guess we have to wait until the CA arrives, now.

Comment by Jiří Maršík [ 03/Apr/13 4:28 AM ]

I have also added the test case, the new patch INomSwap-vectors-maps-with-test.patch contains both the fix and the test case. I have just signed the CA and I plan to post it today.

Comment by Jiří Maršík [ 09/Apr/13 10:55 AM ]

OK, the CA has arrived and been processed.

http://clojure.org/contributing

  • Jiri Marsik (jirkamarsik)
Comment by Nada Amin [ 10/Apr/13 3:32 AM ]

Applied as https://github.com/clojure/core.logic/commit/d73c836c0d4bab2af12b4bdedb31daad4a661fb6

Thanks!





Generated at Sat Oct 25 14:20:15 CDT 2014 using JIRA 4.4#649-r158309.