On May 15, 2014, at 1:03 PM, Reid Draper <reiddra...@gmail.com> wrote:

> Sorry you ran into an issue, Steve. I like your idea of including more 
> information in the ex-info data. Is there a specific generator you're having 
> trouble writing without such-that? In general, I've found that it's a 
> code-smell if you need such-that to retry that many times. Happy to help 
> explore other ways to write these generators.

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.

Now, if you could provide an efficient AND generator combinator, that would 
solve all my problems.  :-)

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.

I'd be happy to consider any suggestions.

Thanks,
Steve Miner


[1] https://github.com/miner/herbert


-- 
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.

Reply via email to