Skip to content

Instantly share code, notes, and snippets.

@avital
Created December 15, 2009 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avital/257019 to your computer and use it in GitHub Desktop.
Save avital/257019 to your computer and use it in GitHub Desktop.
* Function call: (link-elements-in-partition partition el1 el2)
#{#{1 2} #{3 4 5}}
** partition
#{#{1 2} #{3 4 5}}
** el1
2
** el2
4
** (let [c1 (containing-class partition el1) c2 (containing-class partition el2)] (cond (and (not c1) (not c2)) (conj partition #{el2 el1}) (and c1 (not c2)) (add-to-class partition c1 el2) (and c2 (not c1)) (add-to-class partition c2 el1) (and (and c1 c2) (not= c2 c2)) (conj (disj partition c1 c2) (union c1 c2)) :else partition))
#{#{1 2} #{3 4 5}}
*** Function call: (containing-class partition el)
#{1 2}
**** partition
#{#{1 2} #{3 4 5}}
**** el
2
**** (first (for [class partition :when (some #{el} class)] class))
#{1 2}
***** (for [class partition :when (some #{el} class)] class)
(#{1 2})
***** class
#{1 2}
*** Function call: (containing-class partition el)
#{3 4 5}
**** partition
#{#{1 2} #{3 4 5}}
**** el
4
**** (first (for [class partition :when (some #{el} class)] class))
#{3 4 5}
***** (for [class partition :when (some #{el} class)] class)
(#{3 4 5})
***** class
#{3 4 5}
*** (cond (and (not c1) (not c2)) (conj partition #{el2 el1}) (and c1 (not c2)) (add-to-class partition c1 el2) (and c2 (not c1)) (add-to-class partition c2 el1) (and (and c1 c2) (not= c2 c2)) (conj (disj partition c1 c2) (union c1 c2)) :else partition)
#{#{1 2} #{3 4 5}}
**** (and (not c1) (not c2))
false
***** (not c1)
false
****** c1
#{1 2}
**** (and c1 (not c2))
false
***** c1
#{1 2}
***** (not c2)
false
****** c2
#{3 4 5}
**** (and c2 (not c1))
false
***** c2
#{3 4 5}
***** (not c1)
false
****** c1
#{1 2}
**** (and (and c1 c2) (not= c2 c2))
false
***** (and c1 c2)
#{3 4 5}
****** c1
#{1 2}
****** c2
#{3 4 5}
***** (not= c2 c2)
false
****** c2
#{3 4 5}
****** c2
#{3 4 5}
**** partition
#{#{1 2} #{3 4 5}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment