This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-06
Channels
- # announcements (4)
- # beginners (132)
- # calva (37)
- # chlorine-clover (60)
- # cider (1)
- # clara (12)
- # clj-kondo (40)
- # cljs-dev (109)
- # clojure (76)
- # clojure-dev (19)
- # clojure-europe (8)
- # clojure-france (17)
- # clojure-nl (4)
- # clojure-sg (1)
- # clojure-spec (14)
- # clojure-uk (7)
- # clojurescript (98)
- # conjure (96)
- # cursive (15)
- # data-science (2)
- # datalog (11)
- # datomic (24)
- # emacs (17)
- # figwheel-main (3)
- # fulcro (45)
- # jobs-discuss (1)
- # kaocha (3)
- # malli (2)
- # nrepl (1)
- # off-topic (135)
- # portal (2)
- # re-frame (17)
- # reagent (11)
- # reitit (4)
- # sci (60)
- # shadow-cljs (75)
- # spacemacs (3)
- # sql (32)
- # tools-deps (79)
- # vim (88)
- # xtdb (4)
A question about the syntax in :require
in the ns
function: Is :require
a function (looks like it because of the parentheses) and if yes, what does this function do, called with the requirements vector as an argument?
That's probably a question more suitable for #beginners . :require
is not a function (and neither is ns
, actually -- it's a macro), perhaps clojuredocs can help: https://clojuredocs.org/clojure.core/ns
it's not as weird as you might think though, ns
literally turns a :require
clause into a call to the require
function - the only difference is whether symbols are evaluated
Why does (true? [])
returns false
but (when [] :execute)
returns :execute
?
I was surprised by this output and tried to find an answer in the docs, but wasn't able to. Here's the output from a REPL:
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_91-b14
=> (true? [])
=> false
=> (when [] :execute)
=> :execute
I expected when to return nil because []
is falsy
. What is happening here?hmm, I missed that. Thanks Dmitry !
If I’ve done (require '(some.ns :as foo))
and I’m handed a qualified keyword like :foo/bar
, how would I expand that qualified keyword to it’s canonical namespace? i.e. :some.ns/bar
I poked around the ns-*
functions but I seem to be missing something obvious about how to do this.
Is it possible to terminate IReduceInit
, e.g.
(transduce
xform
(fn foo
([_ v] (if (side-effect! v)
(println "ok")
(println "terminated"
(terminate reducible))))
([_] (println "done")))
nil reducible)
Bringing this question here, why is the following implementation of update-in
slightly slower than the core implementation? The difference is very minor, about 5ns slower per key, but it's still there.
(defn- up
[m ks f args]
(let [[k & ks] ks]
(if ks
(assoc m k (up (get m k) ks f args))
(assoc m k (apply f (get m k) args)))))
(defn update-in
([m ks f & args]
(up m ks f args)))
based on the source of the original, if I'm reading correctly, it must be the var lookup of up
inside the recursive call
where the let binding is used in place without need for runtime lookup
I'm not seeing other differences
Shouldn't that be eliminated if we use direct linking? the Clojure jar itself is directly linked, no?
I wouldn't be surprised if that were the case
Seems like it does. Cheated by adding ^:const
to up and got the same performance as update-in
I didn't think const was supposed to do that...
I don't think it does
my understanding is const tells the compiler it's allowed to inline, but I didn't think it would do so for data that couldn't directly be compiled into the bytecode
Any way, while an ugly hack, this also reaches the same performance:
(let [up (fn up
[m ks f args]
(let [[k & ks] ks]
(if ks
(assoc m k (up (get m k) ks f args))
(assoc m k (apply f (get m k) args)))))]
(defn update-in
([m ks f & args]
(up m ks f args))))
I still don't understand why it's not slightly faster as it's supposed to do less allocationsI guess the reference to the function could be compiled into bytecode (vs. the var which is then looked up)
the right answer here is to compare the bytecode, not guess
once again my curiosity must overcome my laziness
my guess is that the difference is really something related to jvm inlining scope and the jit
with a var with direct linking you've split the code into two methods and that may result in different characteristics than what happens when created in the let (harder for inlining to "see" all of it or something like that). this can also be very jvm version sensitive as that stuff is improved all the time
there are a bunch of jvm flags that allow you to see the inlniing work and I've found those can be pretty interesting to watch for stuff like this (presuming that guess to the difference is correct)
oh yeah, I vaguely recall a talk by a guy from the JRuby team about "mechanical sympathy" that covered this in some depth
we occasionally have had issues in CLJ where the addition of error message code blew the inlining budget and made things much slower
I know people like to make fun of the whole perf over error msgs thing but it's an actual tradeoff
@ben.sless are you direct linking the core version?
@ben.sless then you have avoided a var lookup
would kind of like to see the actual bytecode too
the bytecode is typically not actually representable in Java
yeah, the ^:const thing is just wrong
I have never seen anyone asking a question and :const came up where it was being used correctly. Never
the people that understand how it works don't ask questions about it :)
that is kind of the thing, I mean people asking other questions where it just sort of comes up that they are using const
to that point, deftype
is a bit like that:
Note well that mutable fields are extremely difficult to use
correctly, and are present only to facilitate the building of higher
level constructs, such as Clojure's reference types, in Clojure
itself. They are for experts only - if the semantics and
implications of :volatile-mutable or :unsynchronized-mutable are not
immediately apparent to you, you should not be using them.
There be dragons but its not clear how you could learn about how to tame them. I suppose the same for ^:const
. If you're not already an expert, how do you become onefor starters, when do you need those features?
there's a good book which you could consider the rest of deftype
's doc string, elided for brevity and to avoid plagiarism, Java Concurrency In Practice
I've noticed a funny drawback to learning by "following your nose" (something I do a lot), where the amount of documentation needed to describe a narrow and mostly unneeded feature accurately increases your chance of trying it, because it takes up so many pages of the docs you are skimming
given that effect (something that I hope has a name), keeping your references to things most people shouldn't use as terse as possible is a good practice
(reading code instead of docs helps too :D)
https://github.com/onyx-platform/onyx/blob/0.14.x/src/onyx/messaging/aeron/status_publisher.clj#L16-L33 now that's a deftype
Hey, folks. I have a podcast about Software Engineering called The Virtual World. I'm uploading my interview with Eric Normand today and was wondering if you folks had any ideas for other guests that could be on the podcast. Is anyone in contact with David Nolen? I would love to have him on to talk about Clojurescript.
Hey I’m looking for recommendations for building a cross platform desktop app. The app requirements are interaction with a custom hardware driver and charting ability for Windows and Linux mainly with MacOS a nice to have but not required. If anybody has experience I would love to hear about it!
I think your big options are Swing (seesaw is a Clojure lib), JavaFX (couple clojure libs out there and some big projects hav succeeded with that), and Electron which would be ClojureScript I believe, not sure if there are good flagship examples there
I was leaning towards electron as i have ClojureScript experience but I should check out what JavaFX has to offer before I reject it. Thanks @U064X3EF3 for the suggestions.
this is my electron + cljs (+ rust) project for reference https://github.com/valerauko/gitegylet
or less well-known, something like Vaadin (Datomic console is one example I know of)
Oh that’s a new one to me thanks.
There’s some headway in the native space on mac with react-native-macos. Though I don’t think it’s anywhere near complete in terms of library support.
for JavaFX, I'd suggest looking at Defold, which is a game editor created by King that is written in Clojure and has been open sourced