On 6 September 2017 at 11:01, Cecil Westerhof <cldwester...@gmail.com> wrote:
> With the help of this list I rewrote it to: > (def digits > (apply str (map char (range (int \0) (inc (int \9)))))) > (def hex-digits > (apply str digits (map char (range (int \A) (inc (int \F)))))) > > (defn create-pin > ([] (create-pin 8)) > ([n] > {:pre [(<= n 16) > (>= n 4)]} > (reduce str (repeatedly n #(rand-nth digits))))) > > (defn create-pin-hex > ([] (create-pin-hex 8)) > ([n] > {:pre [(<= n 16) > (>= n 4)]} > (reduce str (repeatedly n #(rand-nth hex-digits))))) > > Indention is not great: I have to find out how to modify emacs for it. > > By the way does has clojure something like super? Using: > (defn create-pin-hex > ([] (create-pin-hex 8)) > > is asking for trouble. After copy/pasting from create-pin I almost forgot > to change it. > > If your base function takes chars as its first argument, you can use partial: (defn create-pin-base ([chars] (create-pin chars 8)) ([chars n] {:pre [(<= 4 n 16)]} (apply str (repeatedly n #(rand-nth chars))))) (def create-pin (partial create-pin-base digits)) (def create-pin-hex (partial create-pin-base hex-digits)) -- 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.