People complain about stack traces, but precisely the point of having stack 
traces is that if a pre-condition fails, you don't look at the function 
with the pre-condition, you look at the function that was calling it. 
Duplicating pre-conditions to callers, as a general pattern, would scale 
very badly.

On Thursday, February 19, 2015 at 4:35:54 AM UTC-8, Cecil Westerhof wrote:
>
> I have two different functions for the same functionality. I would like to 
> share the pre-conditions between them.
>
> The general function is:
>     (defn test-lucky-numbers-general
>       "Performance test of lucky numbers general"
>       [fn desc nr]
>       {:pre [(>= nr 1)
>              (<= nr 7)]}
>       (println desc)
>       (dotimes [i 25]
>         (let [lucky (time (fn 10))]))
>       (println)
>       (dotimes [i nr]
>         (time
>           (let [upto (int (Math/pow 10 (inc i)))]
>             (printf "With upto %d there are %d lucky numbers\n" upto 
> (count (fn upto)))))
>         (println)))
>
>
> The functions themselves are:
> ​    (defn test-lucky-numbers
>       "Performance test of lucky numbers"
>       ([]
>        (test-lucky-numbers 6))
>       ([nr]
>        (test-lucky-numbers-general lucky-numbers "Testing performance 
> lucky-numbers" nr)))
> and:
>     (defn test-lucky-numbers-3
>       "Performance test of lucky numbers (3)"
>       ([]
>        (test-lucky-numbers-3 6))
>       ([nr]
>        (test-lucky-numbers-general lucky-numbers-3 "Testing performance 
> lucky-numbers-3" nr)))
> ​
>
> And to call all test functions I have:
>     (defn test-lucky-numbers-all
>       "Test all lucky number performance"
>       ([]
>        (test-lucky-numbers-all 6))
>       ([nr]
>        (test-lucky-numbers nr)
>        (test-lucky-numbers-3 nr)))
>
>
> When I call a function with the wrong parameter, I get an error from 
> test-lucky-numbers-general, but I need it from the calling function. I 
> could copy the pre-condition to all functions, but that is not really DRY. 
> Is there a way I can share the pre-conditions with all (at this moment) 
> four functions?
>
>
> The first dotimes in test-lucky-numbers-general is to warm-up the JVM. Is 
> there a way to know if this is already done for the function that is given? 
> Then it could be done only when necessary.
>
> -- 
> Cecil Westerhof
>  

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