Re: Using type to change the behaviour of a function

2015-02-21 Thread Leon Grapenthin
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

Re: Using type to change the behaviour of a function

2015-02-19 Thread Tassilo Horn
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

Re: Using type to change the behaviour of a function

2015-02-19 Thread Fluid Dynamics
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

Re: Using type to change the behaviour of a function

2015-02-19 Thread Tassilo Horn
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

Re: Using type to change the behaviour of a function

2015-02-19 Thread Justin Smith
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

Using type to change the behaviour of a function

2015-02-19 Thread Cecil Westerhof
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 (*