Fork me on GitHub

What’s the history behind and the stdlib they have almost the exact same API, except that priority-map has a few extra fns (peek, pop, keyfns, access to underlying set, etc.), but none that wouldn’t be relatively straightforward to write yourself. Some prominent libraries depend on priority-map, especially Is there a reason to reach for one or the other?


having not really used either, this is mentioned on priority-map link: "A priority map is very similar to a sorted map, but whereas a sorted map produces a sequence of the entries sorted by key, a priority map produces the entries sorted by value." - so, one sorts by key, other by value?


user=> (apply priority-map mymap)
{:y 10, :x 20, :z 30}
user=> (apply sorted-map mymap)
{:x 20, :y 10, :z 30}
user=> mymap
[:z 30 :y 10 :x 20]

🙏 1

Question: Do generative tests with clojure spec only work(or work best) on computers with large amounts of CPU and RAM? If you have a large test suite... it might be problematic having it all be generative, right?

Sam Ritchie14:03:21

I haven't found that to be the case!

Sam Ritchie14:03:52

7000 tests, many of them generative, takes 4 minutes on free github CI


what kind of specs I wonder? do you have specs for nested maps? how many iterations per test?


is it open source? can I have a look?

Sam Ritchie17:03:49

sure, tons of tests! I usually do 100 per test; lower for some of the big ones, like polynomial GCD

Sam Ritchie17:03:39

I use the checking macro in chuck a bunch, so a search for that turns up many. some of these are used all over, since the functions in sicmutils.laws for example run a full battery of generative tests given some type generator


cool... thanks 🍻


Core language / clojure dev question: has there been any consideration of being able to set metadata on keywords? Right now you can't because they don't implement IObj, but could that conceivably change in the future without breaking something huge?


I ask because it occurs to me that keywords often encode domain knowledge, and setting metadata on them could make it accessible to multiple different tools like spec, malli, docs, etc.


Current keywords are identical in memory, so equality check is just pointer equality, i.e. very fast.


I think "registries" are effectively the technique for that


the keyword can be looked up in some map to find data about what it represents


> I ask because it occurs to me that keywords often encode domain knowledge, and setting metadata on them could make it accessible to multiple different tools like spec, malli, docs, etc. This would seem to me a workaround for malli/clojure.spec oversights which didn't make certain things first-class It's cleaner to fix those instead :)


could you give an example?


spec/def could accept a docstring argument (to be kept e.g. in an atom registry, just like specs), but it doesn't So the simplest options when facing such an obstacle are 1) making an issue, 2) making your own wrapper/helper (which I did some years ago, and keeps being a decent solution)

Alex Miller (Clojure team)15:03:40

keywords are interned and reused so they cannot have metadata as that would have cross-talk

Alex Miller (Clojure team)15:03:41

symbols are not interned and can have metadata, and also support functional lookup like keywords, so that's an option in some cases


I had figured there was likely a compelling reason for it. Thanks for the explanation!


you can create keywords from symbols, and symbols can have metadata. So you might think you could smuggle some metadata in that way. But there’s an explicit path that will throw that away. (in case you were looking at that as a backdoor for metadata)


Yeah, it seems like symbols align better with the notion I had in mind, but I will need to think a bit more about the kw <> symbol relationship in order to have a more concrete idea

Joshua Suskalo16:03:29

more or less it's 1:1 on equality semantics, but it's 1:N from keywords to symbols in terms of identity semantics, which is why you can have meta on symbols. Otherwise they're very similar. The biggest advantage to using keywords (besides equality performance) is we're more used to seeing them in code, although both of them require you to write namespace+name prefixed by one character.


Yeah, to give just one example I can think of, it is interesting that :syms destructuring is supported just as much as :keys but I feel like I've never used it myself and can't recall the last time I saw it in source code I've read.

Joshua Suskalo17:03:29

yeah I didn't realize that was a thing


I know I'm 2 weeks late here, but in case you haven't looked, I think it's interesting to look at the implementation of clojure.lang.Keyword. It's a wrapper around Symbol and then it sits in the static HashMap so that the same keyword always returns the same object. The main difference from symbol is that it changes the hashcode by a constant value (`0x9e3779b9`)


Also, it has to wrap, because of the problem with IObj extending IMeta