On May 15, 2014, at 2:08 PM, Steve Miner <stevemi...@gmail.com> wrote:
> I'm generating generators from schemas [1]. I have generators for all my > simple schemas -- "int" corresponds to gen/int, etc. The tougher case is > when I have to convert a conjunction of schema expressions into a generator. > For example, a schema (and int pos) specifies a positive integer, essentially > like testing (fn [x] (and (integer? x) (pos? x)). > > My current implementation finds some element of the AND that I can map to a > generator and uses such-that to filter against a predicate created from the > rest of the AND elements. > > A simple example does something like this... > > (make-generator '(and int pos odd)) > ---> (gen/such-that (make-predicate '(and pos odd)) (make-generator 'int)) > ---> (gen/such-that (fn [x] (and (pos? x) (odd? x))) gen/int) > > Of course, it would be better to use gen/s-pos-int. I'm thinking that I need > to look for a few common combinations of simple schemas, especially if > there's already a good generator for those cases. > > However, I still need to try to handle the general case, and it looks like > the such-that approach will have to be my fallback position. I'll probably > give the user the option of adding custom generators to match more > complicated schema expressions. Yes, I think you're thinking about this correctly. And in some cases, you may be better off just wasting some CPU cycles and using such-that, just like you are. It really depends on how complex you want your library to be. > > Now, if you could provide an efficient AND generator combinator, that would > solve all my problems. :-) I'll give this some thought :) > > It occurs to me that automatically deriving generators is something like > running a predicate backwards so maybe there's a way to do it with > core.logic, but I haven't tried to do that yet. Let me know how this goes. Reid -- 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/d/optout.