This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-18
Channels
- # announcements (6)
- # babashka (16)
- # beginners (194)
- # calva (20)
- # cider (34)
- # clj-kondo (38)
- # clojure (89)
- # clojure-europe (10)
- # clojure-finland (15)
- # clojure-italy (2)
- # clojure-nl (15)
- # clojure-sg (7)
- # clojure-spec (15)
- # clojure-uk (86)
- # clojurebridge (1)
- # clojurescript (60)
- # community-development (11)
- # conjure (13)
- # core-async (48)
- # core-typed (3)
- # cursive (22)
- # datascript (8)
- # datomic (40)
- # duct (11)
- # emacs (3)
- # figwheel-main (22)
- # fulcro (45)
- # graphql (1)
- # helix (9)
- # hoplon (15)
- # hugsql (7)
- # jobs-discuss (47)
- # juxt (7)
- # kaocha (21)
- # luminus (1)
- # malli (13)
- # meander (2)
- # off-topic (52)
- # parinfer (19)
- # re-frame (66)
- # reagent (1)
- # reitit (3)
- # ring-swagger (1)
- # rum (2)
- # shadow-cljs (72)
- # spacemacs (5)
- # sql (4)
- # timbre (5)
- # tools-deps (15)
- # vim (5)
- # vrac (7)
Hello, if I understand how clojure treats map literals, when a literal has more than 8 entries it builds an hash-map else an array-map. Can I easily change this? for exemple use hash-map only for literals that have more than 32 entries. thank you
using a map when you need key order doesn’t sound right
if you want you could always keep the order as a property of item in the map, then sort it after vectorising it
What does not sound right to me is to lose the ordering of key when passing a map literal to a macro, I cannot really see a benefit for this.
If it was just seeing the map literal “as is”, you’d be stuck with string concatenation
yes of course, but in this case I think we are throwing a potentially usefull information a bit to early
Maps are un-ordered data structures… Don’t rely on key order in any situation, I think that’s the general advice
Yes I agree, and i'm using map this way 99% of the time. It is just in this particular context that I came to think about this.
I understand… I’d try using vectors and see if they can solve the problem; what exactly is the macro trying to achieve?
> Maps are un-ordered data structures…
Not entirely true, clojure provides sorted-map
and sorted-map-by
there’s just no data literal support for it…
(apply sorted-map (mapcat vector (range 100) (range 100)))
@U06HHF230 I was referring to the regular maps with literals 🙂 but yes, that’s correct
maybe keeping insertion order for maps will not yield to significant performance penalty
There is also https://github.com/clj-commons/ordered for Clojure/Java, for preserving insertion order in maps.
The only way I can think of to make those data structures used for normal map literal syntax in Clojure is to modify Clojure itself, which you are free to do on your own local copy, but that won't help you distribute a macro that relies on that to others, unless they also have your modified version of Clojure.
You can use tagged literals to create a literal syntax for insertion-ordered maps, and in fact the ordered library I linked above already has that, e.g. #ordered [[:a 1] [:c 3]] is (IIRC) the literal syntax for an ordered map with key :a and value 1 inserted first.
regarding map literals: the creation of the concrete map happens before any macro code is invoked, so the solution here has to be not using a standard map literal
@U0CMVHBL2 thank you for your ideas and links. It is nice but I really need raw map syntax literals, so I probably will go with trying to fork clojure.
@U051SS2EU yes I'm afraid there is no straightforward solutions to my problem
As long as you have 0 expectation that the changes in your fork will ever be merged into the official version of Clojure, that approach should work fine
> fork clojure
really?!?!
Surely it’s preferable just martial from a seq of pairs into an ordered-map
.
When clojure 1.11.0 comes along will you want to rebuild clojure with your patch applied?
Hey, to each their own. They may decide that making their own local modification to Clojure has disadvantages later, but I have heard that multiple companies and dev groups using Clojure use a locally-patched version of it.
@U0CMVHBL2 yes I do not have any expectations for my changes to be merged 🙂 !
@U06HHF230 I think forking clojure is not such an esoteric thing, even if not so much people seems to do it. rebuilding when a new release comes is not so frequent after all. I think maybe it is more interesting to do this than to argue for a public change.
It’s totally doable; I just very much doubt it’s worth it; for something that’s entirely achievable in the existing clojure ecosystem.
@U06HHF230 the thing is that I really want to use raw map literals 🙂 (this is the start of the discussion) , so no it is not possible in the current clojure ecosystem.
Sure, I just meant your macro (tracking order) would be achievable without them e.g:
(defmacro mymacro [other-param & args] `(ordered-map ~@args))
(mymacro :other-param
"one" 1 "two" 2 "three") ;; => {"one" 1 "two" 2 "three" 3}
You’d need to fork clojure
Why do you need to do it?
has anyone tried using clojure to make a game server library?
p2p with websockets if possible
I built this to play a board game with friends online: https://github.com/phronmophobic/wavelength_helper/tree/networking server: https://github.com/phronmophobic/wavelength_helper/blob/networking/src/wavelength_server/core.clj client: https://github.com/phronmophobic/wavelength_helper/blob/networking/resources/public/index.html It uses a central server to broadcast data between browsers. I’ve looked into using tech like WebRTC, but you still need some form of communication to set up connections and for multiplayers, you need n^2 connections if everyone is connected p2p
hi! am super rusty, feel like my brain's rotted a bit since i last wrote some clj. what's the canonical way to do the following: given two vectors, eg: [1 2 3] [4 5 6 7 8], i want to take for each element of the first, create pairs, so the output would be: [[1 4] [1 5] [1 6] [1 7] [1 8] [2 4] [2 5] [2 6] [2 7] [2 8] [3 4] [3 5] [3 6] [3 7] [3 8]] doing it with loop would be easy, but i am sure there must be a better way.
for
(ins)user=> (for [x [1 2 3] y [4 5 6 7 8]] [x y])
([1 4] [1 5] [1 6] [1 7] [1 8] [2 4] [2 5] [2 6] [2 7] [2 8] [3 4] [3 5] [3 6] [3 7] [3 8])
doh. perfect. thank you. spent a good 20 mins with map and lambdas :face_with_rolling_eyes:
the map/lambda version
(ins)user=> (mapcat (fn [x] (map (fn [y] [x y]) [4 5 6 7 8])) [1 2 3])
([1 4] [1 5] [1 6] [1 7] [1 8] [2 4] [2 5] [2 6] [2 7] [2 8] [3 4] [3 5] [3 6] [3 7] [3 8])
for is definitely nicer
In general, when using threading macros, starting with an initial sequence seq, which syntax is preferred:
it's a style question - the thing I ask myself is whether I imagine the first fn as the "source" of the data contextually, or the original sequence
usually it's the latter, but not always
That was sort of what I was thinking, but that seemed rather subjective. But I guess, isn't most code?
I was looking at the question previously... you might also want to check out the clojure.math.combinatorics/cartesian-product function which does the same thing and may be more understandable.
Nice to join Clojurian Slack again, it’s been a while. Glad to see activity is pretty darn good!
How do I call the "correct signature" here?
(java.nio.file.Files/copy
( "deps.edn")
(java.nio.file.Paths/get "tmp"))
Execution error (ClassCastException) at user/eval221010 (form-init2777453331497094601.clj:2).
java.io.BufferedInputStream cannot be cast to java.nio.file.Path
java.nio.file.Files/copy
has 3 signatures:
a- Path source, Path target, CopyOption... options
b- InputStream source, OutputStream sink
c- InputStream in, Path target, CopyOption... options
With 2 arguments, it end up into a
When I try using ^"[Ljava.nio.file.CopyOption;" (into-array (Class/forName "[Ljava.nio.file.CopyOption;") [])
as 3 arg it get me
Execution error (ClassCastException) at user/eval221072 (form-init2777453331497094601.clj:2).
java.lang.String cannot be cast to java.net.URI
Which I really can't understandI have an example of calling this method in some code I'm in and I'm using:
^"[Ljava.nio.file.CopyOption;" (into-array CopyOption [StandardCopyOption/COPY_ATTRIBUTES StandardCopyOption/REPLACE_EXISTING])
I think the bug in your example is that you're passing the array class in into-array, but there you want just the class
I'm not sure how to square that with the error you're getting, which almost sounds like something else
Okay. I did it. But there is some issue with cursive/nrepl too.
Also: i find io/copy
😓
io/copy
is based on a much older version of the JDK and is not as good or as featured as the newer JDK methods, fyi
https://github.blog/2020-06-18-introducing-github-super-linter-one-linter-to-rule-them-all/ maybe needs some Clojure linting? @borkdude
thanks, I see someone has made an issue here: https://github.com/github/super-linter/issues/111
Seems someone worked on it already! 🙂 https://github.com/github/super-linter/pull/197
what's the best library for HMAC signing a ring response - or is there a foolproof way to do it with interop?
it looks like a good start, thanks
import accepts but doesn't require unquoted symbols btw :D
(this usually doesn't matter, as the right place to do it is in the ns form)
but with that change it works