You don't increase the performance by limiting the input value range in a
pre-condition.
On Thursday, February 19, 2015 at 12:52:38 PM UTC+1, Cecil Westerhof wrote:
>
> I have the following function:
> (defn lucky-numbers
> "Lucky numbers from 1 up-to upto-value.
> 1 <= upto-value
Fluid Dynamics writes:
> (defn lucky-numbers
> ([upto]
> (lucky-numbers false upto))
> ([no-max-check upto]
> {:pre [(if no-max-check true (<= upto (* 10 1000 1000)))]}
> ;; code as before
> ))
>
>
> Why not (or no-max-check (<= upto (* 10 1000 1000)))?
Becaus
On Thursday, February 19, 2015 at 9:54:21 AM UTC-5, Tassilo Horn wrote:
>
> Cecil Westerhof > writes:
>
> Hi!
>
> > At the moment the following:
> > (lucky-numbers 1001)
> > gives:
> > AssertionError Assert failed: (<= upto (* 10 1000 1000))
> user/lucky-numbers
> >
> > But I would like
Cecil Westerhof writes:
Hi!
> At the moment the following:
> (lucky-numbers 1001)
> gives:
> AssertionError Assert failed: (<= upto (* 10 1000 1000)) user/lucky-numbers
>
> But I would like the following to be executed:
> (lucky-numbers :no-max-check 1001)
>
> How would I implement that
one approach would be a multi-method for the condition check that doesn't
enforce the limit on BigInt
user=> (defmulti lucky-numbers-limit type)
#'user/lucky-numbers-limit
user=> (defmethod lucky-numbers-limit :default [n] (< 0 n 1001))
#
user=> (defmethod lucky-numbers-limit clojure.lang.Big
I have the following function:
(defn lucky-numbers
"Lucky numbers from 1 up-to upto-value.
1 <= upto-value <= 10.000.000
http://en.wikipedia.org/wiki/Lucky_number";
; doc-string and pre-condition should match
[upto]
{:pre [(>= upto 1)
(<= upto (*