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 10000001)) #<MultiFn clojure.lang.MultiFn@7533f6b5> user=> (defmethod lucky-numbers-limit clojure.lang.BigInt [n] true) #<MultiFn clojure.lang.MultiFn@7533f6b5> user=> (lucky-numbers-limit 2000000000000) false user=> (lucky-numbers-limit 20000) true user=> (lucky-numbers-limit 2000000000000N) true On Thursday, February 19, 2015 at 3:52:38 AM UTC-8, Cecil Westerhof wrote: > > 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 (* 10 1000 1000))]} > (if (< upto 3) > ; for 1 and 2 the algorithm does not work, so return value > manually > (list 1) > (loop [coll (range 1 (inc upto) 2), survivor-idx 1] > (let [i (nth coll survivor-idx)] > (if (> (count coll) i) > (recur (drop-every-nth coll i) (inc survivor-idx)) > coll))))) > > In this function I limit the maximum value that can be given to the > function. But this is pure for performance reasons. So I would like to have > the possibility to disable it. I read somewhere that you can use types for > this. Sadly I do not remember where. > > At the moment the following: > (lucky-numbers 10000001) > 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 10000001) > > How would I implement that? > > -- > 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.