This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-04
Channels
- # admin-announcements (1)
- # adventofcode (98)
- # announcements (5)
- # asami (3)
- # babashka (24)
- # beginners (51)
- # bitcoin (3)
- # calva (24)
- # clj-kondo (73)
- # cljdoc (5)
- # cljs-dev (2)
- # clojure (15)
- # clojure-czech (3)
- # clojure-dev (27)
- # clojure-europe (7)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-uk (1)
- # conjure (4)
- # cursive (18)
- # datahike (4)
- # datomic (3)
- # deps-new (7)
- # emacs (1)
- # events (10)
- # fulcro (5)
- # honeysql (4)
- # jackdaw (2)
- # java (13)
- # lsp (85)
- # meander (9)
- # membrane (1)
- # minecraft (1)
- # off-topic (45)
- # re-frame (16)
- # sql (17)
- # tools-deps (10)
- # vscode (9)
- # xtdb (8)
hi howdy? when a hashmap is coersed into a seq does it preserve the insertion order of the hashmap?
(for [i (range 10)]
(seq (reduce (fn [m v] (assoc m v v)) {} (range i))))
=>
(nil
([0 0])
([0 0] [1 1])
([0 0] [1 1] [2 2])
([0 0] [1 1] [2 2] [3 3])
([0 0] [1 1] [2 2] [3 3] [4 4])
([0 0] [1 1] [2 2] [3 3] [4 4] [5 5])
([0 0] [1 1] [2 2] [3 3] [4 4] [5 5] [6 6])
([0 0] [1 1] [2 2] [3 3] [4 4] [5 5] [6 6] [7 7])
([0 0] [7 7] [1 1] [4 4] [6 6] [3 3] [2 2] [5 5] [8 8]))
After 8 entries it is converted to an unordered map, so you can't rely on the default hashmap if you want an ordered map.
thanks you! 🙏
Hi All, Let's say I need two webapps that in Production will be deployed in two JVMs. In lower environments, can I convert them into osgi bundles nd deploy in single JVM
I think it's more common to just load the two apps in a single jvm, and not bother with any kind of isolation stuff
monorepos with managed common sets of dependencies are all the rage, that changes the trade offs on the heavy duty isolation machinery a little
Our billing system at work, in production has sort of 3 different services, each running on their own jvms, but in dev I usually load them up in one, no isolation between them
I know people have done osgi stuff with clojure, but I've only seen it come up in mailing list threads, and not for a long time
@hiredman thank you
Why do I get this error message :
; form-init3986065220437913819.clj:10 recur arg for primitive local: prod is not matching primitive, had: Object, needed: long
; Auto-boxing loop arg: prod
on this code :
(ns armstrong-numbers)
(set! *warn-on-reflection* true)
(defn exp [x n]
(loop [x x, n n, prod 1]
(cond (zero? n) prod
(= n 1) (* x prod)
:else
(recur (* x x)
(quot n 2)
(if (even? n) prod (* prod x))))))
(defn armstrong? [num]
(let [digits (map #(Character/digit ^char % 10) (str num))
count-numbers (count digits) ]
(->> digits
(mapv #(exp % count-numbers ))
(reduce +')
(= num))))
The compiler needs to to quite a bit of boxing in exp
, try type hinting the arguments and return values
oke, then I have to think how I do this . For small numbers its int but for real big numbers it schould be another one such as Bigint
If you want to avoid boxed warnings you need to either do unboxed maths or explicitly work with reference types, like bigints
Since you said you'll end up in big int land, then you need to work with them, not primitive maths
Thanks, the annoying message is gone with this code
(ns armstrong-numbers)
(set! *warn-on-reflection* true)
(defn exp [x n]
(loop [x x, n n, prod (bigint 1)]
(cond (zero? n) prod
(= n 1) (*' x prod)
:else
(recur (*' x x)
(quot n 2)
(if (even? n) prod (*' prod x))))))
(defn armstrong? [num]
(let [digits (map #(Character/digit ^char % 10) (str num))
count-numbers (count digits) ]
(->> digits
(mapv #(exp % count-numbers ))
(reduce +')
(= num))))
Why is this a compiler error?
(apply or '(false false false false false))
IT says can't take value of a macro or
, but I'm not sure what this means.apply only works with functions, macros look like functions buy they are something else, they run during the compilation time of code, to generate code
this is a good place to start reading about them: https://clojure.org/reference/macros
but for your specific problem, if your intention is the get the first truthy value on a list, you can do this:
(first (keep identity [false false false true false]))
them you can use: (every? identity [false true false true])
or, if you look for true
specifically, you can do: (every? true? [...])
Think I need to get and read this https://www.manning.com/books/clojure-the-essential-reference
yeah, its a jorney to learn all the core functions, but its very cool, from time to time you find a new function and every changes XD
I learned a lot from a series called "Function of The Day", from Tim Baldridge youtube channel https://www.youtube.com/c/ClojureProgrammingTutorials/videos
Worth pointing out that the reason for or to be a macro is that it allows you to avoid evaluating all the possible arguments. So if you have code like (or (be-friends) (tolerate-differences) (fisticuffs) (launch-nukes)), you can stop on the first truthy value. It could easily be a function if not for that concern.
Hi folks! Where should I request a fix in clojure web?file:///home/berto/Pictures/typo-in-tools_build-guide.png
("ask" is the best place to start overall -- but this page talks in more detail about contributing to parts of Clojure: https://clojure.org/community/contributing_site and for http://clojure.org specifically, you can go straight to GitHub and create an issue)
That's fine. Starting with "ask" is a good habit to get into, even if there are "shortcuts" for some specific things.
Sometimes a post on "ask" will trigger a good discussion about other, related things that might need to be addressed.