Fork me on GitHub

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))))
 ([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]))

Michael W02:12:03

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


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)
          (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))))

Ben Sless11:12:44

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

Ben Sless11:12:28

The solution there would be to use bigints from the get go


oke, can I put the typehints here (defn exp [x n] ?

Ben Sless11:12:53

Yes, but if you're going to work with big ints then you won't need them


sorry now im confused. First you said I need type hints and now I do not need them ?

Ben Sless11:12:24

If you want to avoid boxed warnings you need to either do unboxed maths or explicitly work with reference types, like bigints

Ben Sless11:12:53

Since you said you'll end up in big int land, then you need to work with them, not primitive maths


oke and how do I tell the compiler


I said I could end up in BigInt land

Ben Sless11:12:35

instead of + or * use +' and *'

Ben Sless11:12:06

And wrap the initial prod in bigint


oke, I jhave to find out how to do that


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)
          (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:


Thank you, that makes sense!


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]))


What I was trying to do was to see if they are all true


them you can use: (every? identity [false true false true])


thanks!, that's neater then the reduce i wrote 🙂

🙂 1

or, if you look for true specifically, you can do: (every? true? [...])


Looks like it could be good for discovering core functions


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

👍 1

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.

👍 3

Hi folks! Where should I request a fix in clojure web?file:///home/berto/Pictures/typo-in-tools_build-guide.png


There is typo here, it should be :main 'my.lib.main


("ask" is the best place to start overall -- but this page talks in more detail about contributing to parts of Clojure: and for specifically, you can go straight to GitHub and create an issue)


umm I have already created a question under clojure / docs


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.


Hi Sean, good to know...I am not very much used to the community structure and rules...thx for your guidance & help