2017-09-06 12:44 GMT+02:00 Ray Miller :
> 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
On 6 September 2017 at 11:01, Cecil Westerhof
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))
>
>
2017-09-06 9:58 GMT+02:00 Cecil Westerhof :
> I want to start using Clojure again. I made the following simple function
> to generate a PIN:
> (defn create-pin
> ([] (create-pin 8))
> ([n]
>(let [chars (map char (range (int \0) (inc (int \9]
> (reduce
2017-09-06 11:00 GMT+02:00 Ray Miller :
> On 6 September 2017 at 09:50, Cecil Westerhof
> wrote:
>
>>
>> I am trying the following throwaway code:
>> (defn create-pin
>> ([] (create-pin 8))
>> ([n]
>>{:pre [(<= n 128)
>>(>= n 4)]}
>>(let
On 6 September 2017 at 09:50, Cecil Westerhof
wrote:
>
> I am trying the following throwaway code:
> (defn create-pin
> ([] (create-pin 8))
> ([n]
>{:pre [(<= n 128)
>(>= n 4)]}
>(let [chars (into [] (concat (range (int \0) (inc (int \9))) (range
> (int
2017-09-06 10:13 GMT+02:00 Cecil Westerhof :
> Answering my own question. ;-)
>
> 2017-09-06 9:58 GMT+02:00 Cecil Westerhof :
>
>> The next step is that I want to use hexadecimal numbers. So I should use
>> (range (int \0) (inc (int \9))) combined
2017-09-06 10:35 GMT+02:00 Mark Engelberg :
> You could do that by calling vec on it. But you'd want to move the whole
> let clause outside of the defn, so it is only evaluated once, not every
> time the function is called.
>
Wen the function is finished. ;-)
>
2017-09-06 10:23 GMT+02:00 Colin Yates :
>
> The only way of answering that is with numbers, and I understand
> https://github.com/hugoduncan/criterium/ is excellent for that.
>
> Personally, if I was asking that question I might also be wondering if
> using a mutable data
You could do that by calling vec on it. But you'd want to move the whole
let clause outside of the defn, so it is only evaluated once, not every
time the function is called.
But best, as I said earlier, is just to let chars be "0123456789ABCDEF".
You can call nth on strings, so this is the most
The only way of answering that is with numbers, and I understand
https://github.com/hugoduncan/criterium/ is excellent for that.
Personally, if I was asking that question I might also be wondering if
using a mutable data structure might be worth it
(https://clojure.org/reference/transients).
>
2017-09-06 10:13 GMT+02:00 dennis zhuang :
> 1.Maybe you can use :pre metadata:
>
> (defn create-pin
> ([] (create-pin 8))
> ([n]
>{:pre [(<= n 16)
> (>= n 4)]}
>(let [chars (map char (range (int \0) (inc (int \9]
> (reduce str (repeatedly n
(let [chars "0123456789ABCDEF"] ...)
Replace `reduce` with `apply` to get the performance benefit of using a
string builder behind the scenes.
On Wed, Sep 6, 2017 at 12:58 AM, Cecil Westerhof
wrote:
> I want to start using Clojure again. I made the following simple
Answering my own question. ;-)
2017-09-06 9:58 GMT+02:00 Cecil Westerhof :
> The next step is that I want to use hexadecimal numbers. So I should use
> (range (int \0) (inc (int \9))) combined with (range (int \A) (inc (int
> \F))).
> How would I do that?
>
(concat
1.Maybe you can use :pre metadata:
(defn create-pin
([] (create-pin 8))
([n]
{:pre [(<= n 16)
(>= n 4)]}
(let [chars (map char (range (int \0) (inc (int \9]
(reduce str (repeatedly n #(rand-nth chars))
(create-pin 3)
AssertionError Assert failed: (>= n 4)
Hi Cecil - welcome back!
This would be perfect to test using the new clojure.spec. I can't give
you any advice on the specifics as I have yet to break into it myself,
but the properties of this function are crying out for generative
testing.
Cecil Westerhof writes:
> I want to start using
I want to start using Clojure again. I made the following simple function
to generate a PIN:
(defn create-pin
([] (create-pin 8))
([n]
(let [chars (map char (range (int \0) (inc (int \9]
(reduce str (repeatedly n #(rand-nth chars))
So far so good. But I want to improve a
16 matches
Mail list logo