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 lit
Kotlin offers a lot more than just less verbose code and fixing quirks.
It's a sufficiently large step up over Java that the experience of using it
is completely different, in my experience. The null-safe type system is
worth the price of entry alone. I totally recommend it for Android projects.
S
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 Clojur
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) user/cr
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 (range (int \0) (inc (int
(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 function
> to generate a PIN:
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 #(rand-nth chars))
>
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).
>
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 e
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 structure might be worth
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. ;-)
> But best, as I said earlier,
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 with (range (int \A) (inc (int
>> \F))).
>> How wo
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 \A) (inc (int \F)]
>
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 [chars (into [] (concat (range (int \0) (i
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 str (repeatedly n #(rand-n
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))
>
> (defn create-pin
> ([] (cr
I have a json request coming as:
Headers:
//user defined headers
Content-type: application/json
POST body:
{
"lang": "en",
"result": {
"parameters": {
"city": "Rome",
"name": "Tom"
},
"contexts": [],
"resolvedQuery": "my name i
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 function takes chars as it
I don't know if this is the issue, but the JSON data has it spelled
resolvedQuery, but you spelled it differently in your Clojure code as
:resolvedQuerry (two "r"s in Query instead of one)
In general, using a REPL session to examine the contents of data, or good
old-fashioned debug print statemen
I have:
(def digits
(apply str
(map char (inclusive-range (int \0) (int \9)
and this gives:
"0123456789"
I also have:
(def hex-digits
(apply str
digits
(map char (inclusive-range (int \A) (int \F)
and this gives:
"0123456789ABCDEF"
So
The second to last apply argument doesn't spread args like the last slot.
- terseness from phone
On Sep 6, 2017 8:11 AM, "Cecil Westerhof" wrote:
I have:
(def digits
(apply str
(map char (inclusive-range (int \0) (int \9)
and this gives:
"0123456789"
I also have:
(def
2017-09-06 14:15 GMT+02:00 Gary Trakhman :
> The second to last apply argument doesn't spread args like the last slot.
>
OK, I changed it to:
(def digits
(apply str (map char (inclusive-range (int \0) (int \9)
(def hex-digits
(str digits
(apply str (map char (inclusive-ra
2017-09-06 15:18 GMT+02:00 Cecil Westerhof :
> 2017-09-06 14:15 GMT+02:00 Gary Trakhman :
>
>> The second to last apply argument doesn't spread args like the last slot.
>>
>
> OK, I changed it to:
> (def digits
> (apply str (map char (inclusive-range (int \0) (int \9)
> (def hex-digits
>
Thanks Andy.
I love you man :) . I am new to start a project in clojure. Thanks for the
help. Now, I need not go to Node.js.
Regards
Dinesh
On Wednesday, 6 September 2017 17:06:46 UTC+5:30, Andy Fingerhut wrote:
>
> I don't know if this is the issue, but the JSON data has it spelled
> resol
On Tuesday, September 5, 2017 at 2:03:36 PM UTC-7, Laverne Schrock wrote:
>
>
> On Tuesday, September 5, 2017 at 1:50:59 PM UTC-5, Russell Mull wrote:
>>
>> It's not really clear what you're trying to do, so it's hard to offer
>> further advice.
>>
>
> Essentially, what I'm trying to do is pass
In C, C++ and Java the start function is called main. Why is it called
-main in Clojure?
--
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 member
There is a hint, as to this, in the API doc of gen-class:
https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/gen-class
--
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
Not
2017-09-06 23:27 GMT+02:00 Matching Socks :
> There is a hint, as to this, in the API doc of gen-class:
>
> https://clojure.github.io/clojure/clojure.core-api.html#
> clojure.core/gen-class
>
That explains what happens, not why. ;-)
--
Cecil Westerhof
--
You received this message because you
To define a method in gen-class you need to use a prefix on the function
name, "-" is the default prefix
On Wed, Sep 6, 2017, 14:41 Cecil Westerhof wrote:
> 2017-09-06 23:27 GMT+02:00 Matching Socks :
>
>> There is a hint, as to this, in the API doc of gen-class:
>>
>>
>> https://clojure.github.
2017-09-06 23:42 GMT+02:00 Justin Smith :
> To define a method in gen-class you need to use a prefix on the function
> name, "-" is the default prefix
>
I have to delve a little deeper into that on a rainy day.
> On Wed, Sep 6, 2017, 14:41 Cecil Westerhof wrote:
>
>> 2017-09-06 23:27 GMT+02
Hello! MAGE author here. First off, insn looks super cool! I am excited to
see where the project goes. Are you building it for a particular purpose
like a compiler, or as a curiosity?
With respect to MAGE,
Mage provides fns for yielding the Clojure data that it consumes
...
I ultimately deci
>
> I think you'd be nuts to choose JVM Clojure over Kotlin for serious
> Android development.
>
Yes, totally, just to clarify:
1) I don't recommend using JVM Clojure for Android development apart for
just toy projects.
2) I do recommend using ClojureScript with React Native for Android
devel
Clojure is always launched from Java, there's no way to bootstrap straight
into Clojure from the JVM. So when you launch the JVM, it always starts in
a Java main method. What Clojure does normally, is that it creates the Java
main method for you, and have it call your own main method.
So it goe
33 matches
Mail list logo