Yeah there's no "good" way to do this out of the box. You probably want to define some custom constraints - to perform well you might even need to go so far as to define a new constraint domain.
Things are not at the point where I feel comfortably describing how this can be done as the details are likely to change in the near future. On Mon, Jun 24, 2013 at 12:01 PM, David Rocamora <dro...@gmail.com> wrote: > Hi, > > I've been exploring core.logic while working through The Reasoned Schemer > and would like to be able to describe relationships between IP addresses > and networks that they may or may not be a part of. It's straightforward to > do this in Clojure because I can use bit-and on a network and a mask and on > an IP and a mask. If the results are the same, then the IP is in the > network. At least, that is how I understand it. Here's a predicate function > that does this: > > >> (defn in-network? > > [address network netmask] > > (= (map bit-and network netmask) > > (map bit-and address netmask))) > > >> ;; 192.168.1.3 is in 192.168.1.0/24 > > > > (in-network? > > [192 168 1 3] > > [192 168 1 0] > > [255 255 255 0]) ;; true > > > > ;; but 192.168.100.3 isn't > > > > (in-network? > > [192 168 100 3] > > [192 168 1 0] > > [255 255 255 0]) ;; false > > > It would be cool to be able to do this with core.logic so I could have a > relationship like in-networko that could describe IPs and networks. I'm > running into issues implementing this because lvars aren't supported by the > bitwise operators from Clojure and I can't seem to find anything in > core.logic that does what I need out of the box. The Reasoned Schemer > describes a bunch of bitwise operations, but implementing them seems like > it will involve a lot of work to turn the integers from an IP into lists of > bits and back again. Is there a better way to do this? Any insight would be > appreciated. > > Thanks in advance, > Dave > > -- > -- > 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. > > > -- -- 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.