This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-07
Channels
- # announcements (11)
- # architecture (2)
- # babashka (84)
- # beginners (226)
- # calva (7)
- # chlorine-clover (4)
- # cider (29)
- # clara (17)
- # clj-kondo (23)
- # cljs-dev (58)
- # cljsrn (60)
- # clojure (172)
- # clojure-europe (24)
- # clojure-finland (2)
- # clojure-italy (6)
- # clojure-nl (8)
- # clojure-spec (4)
- # clojure-uk (22)
- # clojurescript (44)
- # conjure (39)
- # core-async (64)
- # cursive (76)
- # data-science (15)
- # duct (3)
- # emacs (2)
- # events (5)
- # fulcro (30)
- # helix (4)
- # jackdaw (5)
- # juxt (1)
- # kaocha (1)
- # leiningen (4)
- # off-topic (9)
- # pathom (22)
- # re-frame (9)
- # reagent (33)
- # reitit (3)
- # ring (10)
- # ring-swagger (2)
- # shadow-cljs (192)
- # spacemacs (27)
- # specter (2)
- # sql (59)
- # vim (2)
Curious question I just thought of that I don’t really know the answer to.
Does Clojure structural sharing mean that if I create copies of the same data structure in a larger data structure there is only one copy in memory, or does each copy take up more memory?
e.g.
(into [] (repeat 10 {:a "foo" :b "bar"}))
is there 10 copies in memory or just one?
I'm not entirely sure, but I think there would be 10 copies. That said, both keywords and strings are interned in Clojure, so there's always only one copy of them
So like, irregardless of structural sharing, there is always only one copy of equal keywords and strings
But structural sharing doesn't share between equal elements, it shares parent node in the tree of changes
@didibus @sofra repeat will give you the same object N times, period
you'll have 10 pointers filling the [] of course, but the map itself is only created once
also you should write your code so the difference wouldn't matter :D
Oh right, that too. But I assumed the question meant more: (repeatedly #(identity {:a "foo"}))
even that, the clojure compiler only creates that hash map literal once, and identity doesn't touch it, just returns it
thanks @noisesmith, I think that clears it up
but agreed with @didibus that this isn't structural sharing - it's just normal behavior
Hum, true true, because the literal can be treated as a value. Okay so: (repeatedly #(hash-map :a "foo"))
then
(though behavior that you're less likely to take advantage of in a language where data isn't immutable)
that would create new hash maps yeah
because hey, you might redefine hash-map
in the middle of realizing that lazy seq, and clojure promises to role with that
(please dont' redefine hash-map in the middle of a lazy-seq or otherwise)
@didibus right, none of these examples so far are structural sharing
If you want to see whether structural sharing is occurring, and exactly how, in Clojure/Java (not ClojureScript), I have a little library that graphically draws the JVM objects in memory used to represent Clojure values. I included a little gallery of example images it created in the docs for the library here: https://github.com/jafingerhut/cljol/blob/master/doc/README-gallery.md
That gallery does not currently contain any examples of structural sharing, but it would be easy to add some.
If you know how to implement the JVM parts of that cljol library in JavaScript, I would consider it. I don't know how to do the necessary object walking and getting current addresses of JavaScript runtime objects.
Hi everyone, I'm using ring-swagger + spec-tools and trying to send array-like query param to the server from Swagger UI: What I want to see: `orders?status=NEW&status=PROGRESS`, but the request was sent in comma-separated form: `orders?status=NEW,PROGRESS` How can I fix it? Seems like I need to add `explode true` in serialization params... Thanks in advance!
If I have a symbol 'foo/bar
where foo
is an aliased ns, how can I find out the full, un-aliased ns?
I guess resolve will give you the var, you may be asking for the alias resolution particularly?
you can use ns-aliases
to resolve aliases
@alexmiller
resolve
, of course. thanks
user=> (alias 'foo 'user)
nil
user=> (ns-name ((ns-aliases *ns*) (symbol (namespace 'foo/bar))))
user
(.name (get (ns-aliases *ns*) 'foo))
using ns-name is better of course
(defn resolve-symb-alias [s]
(symbol (str (get (ns-aliases *ns*) (symbol (namespace s))))
(name s)))
Dear all, I am new to Clojure. I am using Cursive on IntelliJ. I can Build my project but when I try to run it I get this error. Error running 'test (1)': failed to access class com.intellij.execution.impl.ProcessStreamsSynchronizer from class com.intellij.execution.impl.ConsoleViewRunningState (com.intellij.execution.impl.ProcessStreamsSynchronizer is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @7f9a81e8; com.intellij.execution.impl.ConsoleViewRunningState is in unnamed module of loader http://com.intellij.ide.plugins.cl.PluginClassLoader @7b0d6c9c). Does anybody understand what I am doing wrong?
You may find help here, but I wanted to mention that there is also a #cursive channel available.
Sounds like you're not the only one though: https://github.com/cursive-ide/cursive/issues/2350
So, judging by the final comment in that thread, maybe try uninstalling IntelliJ and reinstalling with latest Cursive?
Thanks for the answers. I reinstalled IntelliJ and installed the latest Cursive from https://plugins.jetbrains.com/plugin/8090-cursive. I still get the same error I am afraid.
@U0136V3DUUV That bug is fixed in the latest EAP, doc about how to install EAP versions is here: https://cursive-ide.com/userguide/index.html#eap
… and the alternative (as I did) is installing IntelliJ 2019.3 (Jetbrains lets you download older versions) and using that instead. (BTW - cool to see you’re still lingering around and offering support cfleming. Love the product !)
in terminal emacs, I just want to press a binding and see the ClojureDoc with examples for a symbol under the cursor and I want to see the results in emacs as opposed to having it launch the browser... I had this once but I think it became deprecated... also, it seems that cider has to be running for quite a few approaches to this, which is less than ideal for just reviewing/learning-from code I don't want to start a repl for. Any ideas?
I like terminal emacs so much, but it is so great to get instant docs for the methods of objects in most languages and editors. There has to be a way!
And, of course, it needs to be ClojureDocs as I can't really understand a lot of the official docs for functions.
You may get an answer here, but wanted to let you know there is an #emacs channel too
I figured I'd have better luck here, but is there a respected way to essentially post to two channels?
in the past I've tried the 'posted a question about <this channel's topic> to <some other channel>' but that has produced minimal results, lol.
It depends on what the channels are, and the question. A lot of Clojure users use Emacs, but not all, and Emacs is pretty fragmented in the ways that people use it for Clojure development, too (e.g. Cider vs. not-Cider, spacemacs vs. doom emacs vs. seventeen other make-it-easier-to-give-you-a-canned-setup add-ons that I don't keep track of).
It is not encouraged. If you do not get an answer here for an hour or three, I don't think anyone would object if you repeated on another channel more focused on the question.
the whole thing is making me better at reading the 'official' docs, however, as that is available in a cider-connected repl via cider-doc. so that's good.
@U11BV7MTK do you mean the community docs via cider?
that somehow stopped working for me a while ago, and I think I recall it having been abandoned... but let me try it again.
I would only have to one cider session running at any time, very doable at all times.
the maintainer names the releases after places he releases from. i believe that one was released in india at the conference there
ok, tried to answer this for myself... but where do I see the output of toggle-debug-on-error?
I wonder if the stringp nil error is from my emacs not being able to open a new window.
I know it sounds crazy, but going to the browser... well, it draws me out of the code...
I resolved the issue... it was a cider-nrepl mismatch issue. I have clojuredocs in emacs. Thank you all for the help and the screenshot inspiration of how it should look when I got it working.
the official docs for 'get' state that it
Returns the value mapped to key, not-found or nil if key not present.
but
(get ["foo" "bar"] 1)
returns "bar".@patrickanium when get is used on a vector it uses the key you pass as the index. In this case that returns “bar”
it is interesting this is not at all indicated in the docs. or am I supposed to understand this from the docs?
I still can't figure out if I'm just too dense to understand the official clojure documentation, or if it's somehow scant.
You’re reading the wrong docs. That stuff is more of a reference for functions, to remind you in general what they do. If you want to get a solid understanding of the language, I highly recommend you read the documentation on http://clojure.org. For example, the fact that vectors are functions of their indices is mentioned on this page: https://clojure.org/reference/data_structures
The official Clojure docs are (in)famously terse.
There is http://ClojureDocs.org as you know, and books, tutorials, etc.
but in the 'get' example above... not sure I could/would have realized that it works on vectors, etc.
actually, I'm want to know what I would have to know to be able to deduce how it behaves on other things than maps.
Anyone is free to write and publish docs for all 600+ built-in functions that they like better, of course. Except for http://ClojureDocs.org and books like Clojure: The Essential Reference (which probably took many person-years to write), no one has volunteered.
In fairness, I should say that others have created valuable resources over the last 12 years, but the 2 other main ones I recall right now no longer exist.
Lots of blog articles, etc. on various topics. Creating a reference for all Clojure functions is a lot to write that almost no one takes on, or finishes.
I know, but as someone learning the language... I'm not sure I'm up for writing docs... I need to read them! ;-D
The simple answer is: Don't rely only on the built-in doc strings. Find other sources that help you, too.
ah, ok... I got used to languages like JavaScript where you just casually move through the code and an intelligible explanation appears...
Does the text for get
on http://ClojureDocs.org make it any clearer for you? If so, your project to make that quickly accessible in your IDE is a very good recommendation that you are already following.
and thank god for http://clojuredocs.org.
Thank the contributors. They made it happen. God had nothing to do with it 🙂
Some people find the Clojure cheatsheet useful, not because it provides better docs, but because it organizes (most, not all) of Clojure's built-in functions and macros into related groups: https://jafingerhut.github.io
thank you so much for this cheatsheet. it's a great quiz type thing... look at a function and guess what it does, mouse over for answer. it's inspiring for other things I'm learning.
Sure, glad you find it useful.
plus, knowing which of the 600 aforementioned functions are more likely good to know.
Why does halt-when
not appear to work with sequence
?
(sequence (halt-when odd? vector) [2 2 1 2])
=> (2 2)
It doesn't make sense in the sequence or chan case I think it's a bug that #'into doesn't gel with halt-when
We had this conversation before 🙂 https://clojurians-log.clojureverse.org/aws/2020-02-01
I think it could make sense to expose it. I would like a lazy sequence of results and a secondary value that contains an error, if one occurred.
The result of halt-when's retf would be the end result. Something like this is the alternative, I think.
(def my-seq (sequence xf my-seq))
(doseq [item (filter #(not (error? %)) my-seq)]
(process-item item))
(some error? my-seq)
Presumably [the-sequence failing-val], though, perhaps this is what you're getting at, failing-val may not have been realized yet.
it doesn't compute not because of the realization aspect, but because of the nature of those transducible contexts
can't have the completion function synthesizing things that weren't there and putting them in the channel (Flushing something like partition-all is different)
Anything that is iterative/step based therefore will not work with halt-when, right? It only works for eager reduces.
here is the internal "step" of sequence
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/TransformerIterator.java#L39-L50
I posted a debug to my cider-clojuredocs issue to #cider if anyone is able to look at it https://clojurians.slack.com/archives/C0617A8PQ/p1588888419018300