Starting Clojure again
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 little. I think n should at least be four, but not greater as 16. What is the Clojure way to do this? 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? Is there anything I should do differently? Of-course I make a general function that is then called from create-pin and create-pin-hex. -- 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.
Re: Writing an Android application with Clojure
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. Sometimes a language offers a combination of existing concepts in a coherent package which is somehow greater than the sum of its parts - languages don't have to be innovative to be useful, pleasant and powerful. Clojure itself is such a language. We already had good lisps. We already had good JVM functional languages. We already had languages with persistent data structures. We already had languages with STM, good concurrency support, interactive development and all the rest of it. But the pragmatic combination of those features made (and continues to make) it very compelling. Kotlin is another such language. I think there's a strong case to be made for using React Native for mobile dev, and ClojureScript's story is very good there. But personally I think you'd be nuts to choose JVM Clojure over Kotlin for serious Android development. On 6 September 2017 at 07:04, Didier wrote: > I know Java and C++. A long time ago I worked with Pascal. >> >> What I like about Kotlin is that it is less verbose. And Clojure is >> of-course even less verbose. :-D >> > > Oh yea, and Kotlin exists pretty much only to address Java's verbosity, > and maybe a few small other quirks, and it did a great job at that. But you > won't learn anything new conceptually. All you will learn is a new less > verbose syntax for the same concepts. I honestly just hope Kotlin pushes > future Java versions to improve on their verbosity and quirks, so that we > don't need Kotlin in the future, but Java is not a pain to use anymore. I > like Kotlin, but its also dumb to have a whole new JVM language works the > same conceptually, just because Java never bothered improving on its quirks > and verbosity. > > On Tuesday, 5 September 2017 04:14:33 UTC-7, Cecil Westerhof wrote: >> >> 2017-09-03 20:23 GMT+02:00 Didier : >> >>> Kotlin is actually officialy supported on Android, so definitly a good >>> choice there. >> >> >> I started with Kotlin. I think I first learn to write some applications >> for Android and then decide if I want to switch to Clojure(Script). >> >> >> >> >>> That said, if you know Java, C#, C++, Pascal, or even ActionScript 3, >>> Kotlin brings nothing new to the table conceptually. It does improve on >>> convenience over Java though. >> >> >> I know Java and C++. A long time ago I worked with Pascal. >> >> What I like about Kotlin is that it is less verbose. And Clojure is >> of-course even less verbose. :-D >> >> -- >> 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. > -- 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.
Re: Starting Clojure again
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 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 little. > > I think n should at least be four, but not greater as 16. What is the > Clojure way to do this? > > 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? > > Is there anything I should do differently? > > Of-course I make a general function that is then called from create-pin and > create-pin-hex. > > -- > 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.
Re: Starting Clojure again
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/create-pin (NO_SOURCE_FILE:27) and clojure.spec is great too. 2. you can use concat (concat seq1 seq2) see cheat sheet for clojure: https://clojure.org/api/cheatsheet 2017-09-06 16:10 GMT+08:00 Colin Yates : > 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 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 little. > > > > I think n should at least be four, but not greater as 16. What is the > > Clojure way to do this? > > > > 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? > > > > Is there anything I should do differently? > > > > Of-course I make a general function that is then called from create-pin > and > > create-pin-hex. > > > > -- > > 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. > -- 庄晓丹 Email:killme2...@gmail.com Site: http://fnil.net 不学习,毋宁死 -- 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.
Re: Starting Clojure again
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 \9))) (range (int \A) (inc (int \F By the way. I am using a lazy sequence here. Could it be updated with using a vector when creating very long strings, or is that not a significant performance increase? -- 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.
Re: Starting Clojure again
(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: > (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 little. > > I think n should at least be four, but not greater as 16. What is the > Clojure way to do this? > > 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? > > Is there anything I should do differently? > > Of-course I make a general function that is then called from create-pin > and create-pin-hex. > > -- > 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. > -- 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.
Re: Starting Clojure again
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)) > > (create-pin 3) > AssertionError Assert failed: (>= n 4) user/create-pin (NO_SOURCE_FILE:27) > > > and clojure.spec is great too. > For the moment I will go for :pre, but I will also look into clojure.spec. > 2. you can use concat > > (concat seq1 seq2) > I should have wait a little longer with asking. I already found it. But thanks anyway. -- 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.
Re: Starting Clojure again
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). > By the way. I am using a lazy sequence here. Could it be updated with > using a vector when creating very long strings, or is that not a > significant performance increase? > > -- > 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.
Re: Starting Clojure again
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 efficient way to do a fixed sequence of specific characters. On Wed, Sep 6, 2017 at 1:13 AM, Cecil Westerhof wrote: > 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 \9))) (range (int \A) (inc (int > \F > > > By the way. I am using a lazy sequence here. Could it be updated with > using a vector when creating very long strings, or is that not a > significant performance increase? > > -- > 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. > -- 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.
Re: Starting Clojure again
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 it (https://clojure.org/ > reference/transients). > I am going to look into that. (But first keep experimenting.) > > By the way. I am using a lazy sequence here. Could it be updated with > > using a vector when creating very long strings, or is that not a > > significant performance increase? -- 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.
Re: Starting Clojure again
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, is just to let chars be "0123456789ABCDEF". > You can call nth on strings, so this is the most efficient way to do a > fixed sequence of specific characters. > The reason I use range is that in the future I am going to use long ranges and I think then a range is better as a long string. But that is something to think about. On Wed, Sep 6, 2017 at 1:13 AM, Cecil Westerhof > wrote: > >> 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 \9))) (range (int \A) (inc (int >> \F >> >> >> By the way. I am using a lazy sequence here. Could it be updated with >> using a vector when creating very long strings, or is that not a >> significant performance increase? >> > -- 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.
Re: Starting Clojure again
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 would I do that? >> > > (concat (range (int \0) (inc (int \9))) (range (int \A) (inc (int > \F > > > By the way. I am using a lazy sequence here. Could it be updated with > using a vector when creating very long strings, or is that not a > significant performance increase? > 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)] (println chars) (reduce str (repeatedly n #(rand-nth chars)) When calling: (create-pin 100) I get: [48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70] "5153676752696854666551674951514949484851566570574951687067515570654868486554676769517069506651486970706567695467554866515465547068696955506968516770546849536866694853564951545266554857545648515454" So it looks like chars is filled correctly, but it only uses 0-9 and not A-F. So what am I doing wrong? -- 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.
Re: Starting Clojure again
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)] > (println chars) > (reduce str (repeatedly n #(rand-nth chars)) > > When calling: > (create-pin 100) > > I get: > [48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70] > "51536767526968546665516749515149494848515665705749516870 > 675155706548684865546767695170695066514869707065676954675548 > 665154655470686969555069685167705468495368666948535649515452 > 66554857545648515454" > > So it looks like chars is filled correctly, but it only uses 0-9 and not > A-F. So what am I doing wrong? > The variable you call "chars" is actually a vector of integers, so you are selecting random integers and joining them together into a string. You could try: (let [chars (mapv char (concat (range (int \0) (inc (int \9))) (range (int \A) (inc (int \F)] ...) Ray. -- 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.
Re: Starting Clojure again
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) (inc (int \9))) (range >> (int \A) (inc (int \F)] >> (println chars) >> (reduce str (repeatedly n #(rand-nth chars)) >> >> When calling: >> (create-pin 100) >> >> I get: >> [48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70] >> "5153676752696854666551674951514949484851566570574951687 >> 067515570654868486554676769517069506651486970706567695467554 >> 866515465547068696955506968516770546849536866694853564951545 >> 266554857545648515454" >> >> So it looks like chars is filled correctly, but it only uses 0-9 and not >> A-F. So what am I doing wrong? >> > > The variable you call "chars" is actually a vector of integers, so you are > selecting random integers and joining them together into a string. You > could try: > > (let [chars (mapv char (concat (range (int \0) (inc (int \9))) (range (int > \A) (inc (int \F)] > That does work. I should have looked more carefully, then I would have understand that it was concatenating integers instead of chars. -- 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.
Re: Starting Clojure again
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-nth chars)) > > So far so good. But I want to improve a little. > > I think n should at least be four, but not greater as 16. What is the > Clojure way to do this? > > 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? > > Is there anything I should do differently? > > Of-course I make a general function that is then called from create-pin > and create-pin-hex. > 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. -- 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.
Re: Starting Clojure again
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 > ([] (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.
need help on json format extraction multiple deep
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 is Tom", }, "action": "greetings", }, } I am ble to extract like :lang using following (get-in (json-body-request request {:keywords? true :bigdecimals true}) [:body :lang]) But I am not able to extract :resolvedQuerry. Although I am able to extract :result. I used following code , but I know i am missing something. Please help me out? (get (get-in (json-body-request request {:keywords? true :bigdecimals true}) [:body :result]) :resolvedQuerry)) -- 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.
Re: Starting Clojure again
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 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)) > Works great, thanks. By the way it shows why it is important. You had: (create-pin chars 8)) instead of: (create-pin-base chars 8)) -- 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.
Re: need help on json format extraction multiple deep
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 statements or logging, to print out the contents of intermediate values like from your expression (get-in (json-body-request request {:keywords? true :bigdecimals true}) [:body :result]) :resolvedQuerry), can help debug these kinds of things. Andy On Wed, Sep 6, 2017 at 3:42 AM, dinesh bhardwaj wrote: > 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 is Tom", > > }, > "action": "greetings", > }, > > } > > > I am ble to extract like :lang using following > > (get-in (json-body-request request {:keywords? true :bigdecimals true}) > [:body :lang]) > > But I am not able to extract :resolvedQuerry. Although I am able to extract > :result. I used following code , but I know i am missing something. Please > help me out? > > (get (get-in (json-body-request request {:keywords? true :bigdecimals true}) > [:body :result]) :resolvedQuerry)) > > > -- > 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. > -- 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.
What am I doing wrong
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 far so good. Then I define: (def alphanumerics (apply str digits (map char (inclusive-range (int \A) (int \Z))) (map char (inclusive-range (int \a) (int \z))) )) but this gives: "0123456789clojure.lang.LazySeq@4659426eabcdefghijklmnopqrstuvwxyz" Why does it not give: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" The definition of inclusive-range: (defn inclusive-range ([start end] (inclusive-range start end 1)) ([start end step] (range start (inc end) step))) -- 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.
Re: What am I doing wrong
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 hex-digits (apply str digits (map char (inclusive-range (int \A) (int \F) and this gives: "0123456789ABCDEF" So far so good. Then I define: (def alphanumerics (apply str digits (map char (inclusive-range (int \A) (int \Z))) (map char (inclusive-range (int \a) (int \z))) )) but this gives: "0123456789clojure.lang.LazySeq@4659426eabcdefghijklmnopqrstuvwxyz" Why does it not give: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" The definition of inclusive-range: (defn inclusive-range ([start end] (inclusive-range start end 1)) ([start end step] (range start (inc end) step))) -- 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. -- 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.
Re: What am I doing wrong
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-range (int \A) (int \F)) (def alphanumerics (str digits (apply str (map char (inclusive-range (int \A) (int \Z (apply str (map char (inclusive-range (int \a) (int \z )) That does what it should. I should probably create a function for the apply str … > 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 hex-digits > (apply str > digits > (map char (inclusive-range (int \A) (int \F) > and this gives: > "0123456789ABCDEF" > > So far so good. Then I define: > (def alphanumerics > (apply str > digits > (map char (inclusive-range (int \A) (int \Z))) > (map char (inclusive-range (int \a) (int \z))) > )) > > but this gives: > "0123456789clojure.lang.LazySeq@4659426eabcdefghijklmnopqrstuvwxyz" > > Why does it not give: > "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" > > The definition of inclusive-range: > (defn inclusive-range > ([start end] (inclusive-range start end 1)) > ([start end step] > (range start (inc end) step))) > > -- 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.
Re: What am I doing wrong
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 > (str digits > (apply str (map char (inclusive-range (int \A) (int \F)) > (def alphanumerics > (str digits >(apply str (map char (inclusive-range (int \A) (int \Z >(apply str (map char (inclusive-range (int \a) (int \z >)) > > That does what it should. I should probably create a function for the > apply str … > Done: (defn string-from-range [start end] (apply str(map char (range (int start) (inc (int end)) (def digits (string-from-range \0 \9)) (def hex-digits (str digits (string-from-range \A \F))) (def alphanumerics (str digits (string-from-range \A \Z) (string-from-range \a \z) )) -- 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.
Re: need help on json format extraction multiple deep
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 > 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 statements or logging, to print out the contents > of intermediate values like from your expression (get-in (json-body-request > request {:keywords? true :bigdecimals true}) [:body :result]) > :resolvedQuerry), can help debug these kinds of things. > > Andy > > On Wed, Sep 6, 2017 at 3:42 AM, dinesh bhardwaj > wrote: > >> 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 is Tom", >> >> }, >> "action": "greetings", >> }, >> >> } >> >> >> I am ble to extract like :lang using following >> >> (get-in (json-body-request request {:keywords? true :bigdecimals true}) >> [:body :lang]) >> >> But I am not able to extract :resolvedQuerry. Although I am able to extract >> :result. I used following code , but I know i am missing something. Please >> help me out? >> >> (get (get-in (json-body-request request {:keywords? true :bigdecimals >> true}) [:body :result]) :resolvedQuerry)) >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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.
Re: Question regarding core.logic
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 expressions dynamically to > run*. If I hardcode [x] I'm fine, but if I want to be able to derive the > vector from user input, I'm stuck, since I can't seem to figure out how to > associate a symbol that I pass in with the fresh variable introduced with > fresh. > You want user input to determine the list of logic variables you're passing to 'fresh'? That sounds strange. The analogue in regular Clojure would be to use user input to drive the binding part of a 'let' form. If you want to do code generation go for it, but I'm guessing that's not the right path here. Perhaps you just want to find out a list of things? You could do this by building a list in your logic program and unifying that with the unknown in your run form. - Russ -- 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.
Why is the start function called -main
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 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.
Re: Why is the start function called -main
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 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.
Re: Why is the start function called -main
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 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.
Re: Why is the start function called -main
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.io/clojure/clojure.core-api.html#clojure.core/gen-class >> > > That explains what happens, not why. ;-) > > -- > 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. > -- 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.
Re: Why is the start function called -main
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: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 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.
Re: [ANN] Insn: Functional JVM bytecode generation for Clojure.
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 decided against this approach. I felt that using raw Clojure > data provided more clarity, which is of course subjective. Agreed, it's subjective. The CLR is quite verbose and many parts of the bytecode emission machinery require a lot of configuration to work, and the constructor functions allow me to set a lot of defaults in one place and leave them out of the core emission logic. I got the approach from Kovas Boguta's gamma library and haven't changed it since. Mage will automatically flatten nested bytecode sequences. This is not > necessary in my opinion since you can just use unquote-splicing within an > op sequence. True, but you don't lose anything to flattening bytecode sequences, and being able to return vectors of bytecode (or even nil) from functions is very convenient. In an environment without a stack language (like LLVM), I'd probably reconsider this, but I really like not worrying about the shape of my symbolic bytecode as I generate it. Mage has the concept of named local variables. This isn't quite the case. Locals on the CLR do not have names and compile down to offsets, but MAGE's il/local constructor function will produce a symbolic local variable (just Clojure data like everything else) that will get stitched together by the emission library at the end. I use Clojure's let bindings to cause the same symbolic local to appear in multiple places in the bytecode stream, and they get resolved to the same offset in the final bytecode. Finally, mage seems to require always writing out an assembly .dll to disk > on each emit. Though the README does not demo it, MAGE does support emitting types, modules and assemblies directly into memory. This is how MAGIC is able to live side-by-side with ClojureCLR. That said, the CLR compiler ecosystem is very much oriented around files, so I do end up emitting to disk a lot while developing MAGE and MAGIC to take advantage of disassemblers and other tools. I would also be nice if the mage author would provide some tests More than happy to! Do you mean tests of MAGE in the repo? The most use it gets is in the MAGIC project where it gets used and tested pretty extensively: https://github.com/nasser/magic. I hope than answers some questions! If you're interested in this stuff I've started documenting it in a dev blog over at http://nas.sr/magic/. Again, great work on insn and I am excited to see where it goes! R On Saturday, August 19, 2017 at 12:49:54 PM UTC-4, jgp...@gmail.com wrote: > > While I'm not as familiar with the CLR and its bytecode syntax, from what > I can tell from the README, mage and insn seem to have similar goals and > ideas. > > I'll attempt to summarize the differences that I could find, if the mage > author *nasser* is available I would appreciate his or her input. > > Mage provides fns for yielding the Clojure data that it consumes. At one > point in development I also did this. Something like the following. > > (insn/visit :members [(insn/field [:public] "foo" :int) > (insn/method :init [:int :void] > [[:iload 1] > #_...])]) > > I ultimately decided against this approach. I felt that using raw Clojure > data provided more clarity, which is of course subjective. You can easily > implement these and more application-specific versions yourself if you > desire. I use the library for a couple of unreleased projects and I have > fns named emit-box, emit-proxy-method, etc. > > Mage will automatically flatten nested bytecode sequences. This is not > necessary in my opinion since you can just use unquote-splicing within an > op sequence. > > Mage has the concept of named local variables. I don't know if this is a > CLR concept, I assume this is a convenience feature to avoid having to > refer to method locals by number. If so, I could easily implement this as > it seems to be the same concept as Insn's autogenerated labels. > > Finally, mage seems to require always writing out an assembly .dll to disk > on each emit. Not a big deal, but Insn allows more control in this regard > as your generated classes may exist entirely in memory. > > Anyway, I hope this helped. Again I am only passingly familiar with mage > and I have not read the source code. I would also be nice if the mage > author would provide some tests. :) > > > On Friday, August 18, 2017 at 10:44:54 PM UTC-7, Colin Fleming wrote: >> >> This looks very interesting. How would you compare this to Mage for the >> CLR? Are they essentially equivalent? >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to thi
Re: Writing an Android application with Clojure
> > 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 development, when it make sense, like standard apps which don't need crazy performance, or specific Android gadgetry, and also should work on iOS. 3) Kotlin is definitely a nice Imperative OOP language, which some functional sprinkle. I like it quite a bit. 4) Kotlin is more fun to use then Java, and is an officially supported language on Android, and is a great choice for Android development when ClojureScript + React Native turned out to not be enough. 5) Kotlin will not change your mental model, if you have experience with Java, C#, Pascal, C++, and other static OOP languages with sprinkles of functional programming. If that's not your goal, then there's nothing wrong with it. 6) I haven't used Kotlin enough, and I think its a little too young to know if its choices are actually better then Java's, or C#'s choices. Though probably better then Java's. 7) I recommend when learning new languages, to pick languages which will challenge and enhance your mental models, so I recommend learning Clojure for that alone. 8) If you want to learn Android development, Java or Kotlin will do, but if you already know Java, and you're focused on learning Android, that will be enough, since really its about learning the Android SDK and environment. 9) If you're going to consider building a serious Android App, and ClojureScript + React Native was not enough, then I would consider Kotlin very heavily, as it will probably make it more fun and enjoyable, while still being robust. On Wednesday, 6 September 2017 01:09:27 UTC-7, Colin Fleming wrote: > > 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. > > Sometimes a language offers a combination of existing concepts in a > coherent package which is somehow greater than the sum of its parts - > languages don't have to be innovative to be useful, pleasant and powerful. > Clojure itself is such a language. We already had good lisps. We already > had good JVM functional languages. We already had languages with persistent > data structures. We already had languages with STM, good concurrency > support, interactive development and all the rest of it. But the pragmatic > combination of those features made (and continues to make) it very > compelling. > > Kotlin is another such language. I think there's a strong case to be made > for using React Native for mobile dev, and ClojureScript's story is very > good there. But personally I think you'd be nuts to choose JVM Clojure over > Kotlin for serious Android development. > > On 6 September 2017 at 07:04, Didier > > wrote: > >> I know Java and C++. A long time ago I worked with Pascal. >>> >>> What I like about Kotlin is that it is less verbose. And Clojure is >>> of-course even less verbose. :-D >>> >> >> Oh yea, and Kotlin exists pretty much only to address Java's verbosity, >> and maybe a few small other quirks, and it did a great job at that. But you >> won't learn anything new conceptually. All you will learn is a new less >> verbose syntax for the same concepts. I honestly just hope Kotlin pushes >> future Java versions to improve on their verbosity and quirks, so that we >> don't need Kotlin in the future, but Java is not a pain to use anymore. I >> like Kotlin, but its also dumb to have a whole new JVM language works the >> same conceptually, just because Java never bothered improving on its quirks >> and verbosity. >> >> On Tuesday, 5 September 2017 04:14:33 UTC-7, Cecil Westerhof wrote: >>> >>> 2017-09-03 20:23 GMT+02:00 Didier : >>> Kotlin is actually officialy supported on Android, so definitly a good choice there. >>> >>> >>> I started with Kotlin. I think I first learn to write some applications >>> for Android and then decide if I want to switch to Clojure(Script). >>> >>> >>> >>> That said, if you know Java, C#, C++, Pascal, or even ActionScript 3, Kotlin brings nothing new to the table conceptually. It does improve on convenience over Java though. >>> >>> >>> I know Java and C++. A long time ago I worked with Pascal. >>> >>> What I like about Kotlin is that it is less verbose. And Clojure is >>> of-course even less verbose. :-D >>> >>> -- >>> Cecil Westerhof >>> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> >> Note that posts from new members are moderated - please be patient with
Re: Why is the start function called -main
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 goes: JVM -> Java main method -> Clojure main function. What creates the Java main method for you is the (gen-class) macro. To know which of your Clojure function to have the Java main method it'll generate call, it uses a convention. This convention by default is that it will call the function named "-main". You can choose to change the "-" to any other prefix, but it is "-" by default. The convention forces you to have it end with "name", but lets you choose whatever prefix you want, which is "-" by default. I think you could set the prefix to "" and have your Clojure main function be called simply "main" if you want (never tried it though). Why is it prefixed? Well, the idea of having a prefix is that any Clojure function used for interop, in the sense that it is designed to be called from Java, is prefixed, so you can easily know its purpose is Java interop. So by default, all Clojure function prefixed with "-" can be assumed to be interop functions used by Java. On Wednesday, 6 September 2017 14:56:35 UTC-7, Cecil Westerhof wrote: > > 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: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 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.