This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-04
Channels
- # announcements (1)
- # architecture (18)
- # aws (7)
- # babashka (63)
- # beginners (38)
- # bristol-clojurians (1)
- # circleci (1)
- # clj-kondo (10)
- # clojars (4)
- # clojure (159)
- # clojure-berlin (3)
- # clojure-europe (4)
- # clojure-italy (7)
- # clojure-losangeles (6)
- # clojure-nl (7)
- # clojure-spec (3)
- # clojure-uk (109)
- # clojurescript (54)
- # css (1)
- # cursive (38)
- # data-science (2)
- # datascript (3)
- # datomic (14)
- # docker (2)
- # duct (11)
- # fulcro (47)
- # jobs (8)
- # jobs-discuss (3)
- # kaocha (4)
- # malli (3)
- # nyc (2)
- # off-topic (30)
- # overtone (3)
- # re-frame (17)
- # reagent (33)
- # shadow-cljs (29)
- # spacemacs (3)
- # specter (4)
- # tools-deps (13)
- # xtdb (13)
Hey friends, what are the performance characteristics of swap! ?
I have a program that stores a bunch of state in a single atom, (roughly 30 kb of data once exported to json, but that should grow substantially as the simulation becomes more complex) and calls swap! on that atom a minimum of once per frame, which is roughly 20 times a second.
I wonder partly because I seem to have a pretty bad memory leak, I haven't had time to really search it out yet but I thought I would check if my whole premise was an issue before I search too hard profiling indicates that it comes from the hottest loops, which is where the global atom is being processed and swapped.
Thanks!
swap! is, most likely, not your bottleneck. It’s pointer change. How do you change data structure kept in atom? Problem would rather be in processing data before swap! call, or any code that listens to atom change and processes new value.
I change it lots and lots of ways! Thanks, that makes sense, glad to know I'm not totally misusing swap 😄
Have you tried benchmarking (swap! your-atom your-change-fn)
vs (your-change-fn some-data)
?
I'd suspect your-change-fn
might be a major contributor.
I haven't yet! The profiling made it look like swap was the hotspot and I didn't find any information on if it was ok to run swap dozens of times a second, this narrows my search a lot!
Hi everyone. Is there any way to convey a dynamic var's binding into the body of a list comprehension without using another var?
user=> (def ^:dynamic *foo* 0)
#'user/*foo*
user=> (binding [*foo* 1] *foo*)
1
user=> (binding [*foo* 1] (for [n [1]] *foo*))
(0)
user=> (binding [*foo* 1] (let [p *foo*] (for [n [1]] p)))
(1)
I want the (0)
to show (1)
without doing the last line. I want *foo*
itself to resolve to 1
. Is this possible?The issue here is that the lazy collection returned by for
is realized only outside of the binding.
What is the fastest way to reset the REPL to the state when it is freshly runed? I want be sure all ns are unloaded and I don’t want to lose time for reset REPL each time to be sure if dependencies are correctly reduced.
@kwladyka are you familiar with https://github.com/weavejester/reloaded.repl?
@borkdude I don’t think this is what I need. Does it demand Sierra component? Also the issue is not reloading, but unloading in this case.
I remove dependency from ns dependencies and reload ns. It works. But if I kill REPL and load ns then not.
ok I found manually which dependency make the issue, but anyway I am interested in how to reset the REPL without kill and run again
you probably want https://github.com/clojure/tools.namespace
But first, it will unload (remove) the namespaces that changed to clear out any old definitions.
which i think is what you want
yes, I think you seek refresh
(only affects namespaces), as opposed to reset
(affects a System)
What does one typically do when your deps.edn
includes dependencies that have transitive dependencies that are only available in 3rd party Maven repositories? Is deps
expected to be able to handle this case?
Does anyone here uses postal for sending email by SMTP?
What libraries are people using for testing http calls?
My doubt it was i was able to send a attachment by a inputstream
Because i saw that i can send with http://java.io.File
I haven't use
with postal, but my experience with the jvm generally is that people often assume they need a File when really they could use something more abstract, or not reliant on using a fileystem
eg. io/resource to read from inside a jar, or ByteArrayInputStream to read directly from bytes in memory
oh actually it is not a path ,but http://java.io.File so probably you can use stream too
Remember that (+ [1 2 3]) is erroneous - I wonder why (max [1 2 3]) is not - the result is [1 2 3] even though no ordering of vectors is defined: (max [1 2 3] [4 5 6]) is erroneous as well. I think it would have made more sense to return an error for (max [1 2 3])?
OK? For all pairs of vectors? Which is greater [1 50 0] or [-100 1000 9]?
OK - I tried and got some 1 and minus 1 results - does it make sense? - to me it does not - please explain.
And why does max not use that order then?
It seems that compare is another buggy function - unless you can make sense of that order for any given pair of vectors?
Ha ha - it seems to compare strings?
compare relies on https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html
Yes - I read that - try to explain the math
so max is not a mathematical function?
like I said, max is only for numbers, which is why max doesn't use compare, which is a generic way to compare things
OK - which is intuitively biggest: [0 1] or [1 0]?
sort for example (which doesn't actually use clojure.core/compare, but is built on Comparable) can sort lists of vectors
But one must be biggest if there is an order?
And I guess it is [1 0]
But it makes no sense from a mathematical viewpoint - remember I asked about max
the algorithm is, a vector with fewer elements is always less than a vector with more, and if vectors have the same number they are compared element by element until they differ, returning the first difference
Yes - fine - I wonder what the use of that is
OK - from a mathematical viwepoint there is no ordering
Becausemax is a mathematical function
Do you know what a mathematical ordering is?
I think you may be saying math and mathematical when you mean numeric, but please enlighten me
Anyway - there does not seem to be a such for vectors in clojure - at least it does not apply to the max function
And that was my point - sorry if it was not clear
still isn't clear, you keep saying there isn't a mathematical ordering for vectors, and as far as I know math would be fine with the ordering that is defined
> The notion of order is very general, extending beyond contexts that have an immediate, intuitive feel of sequence or relative quantity. In other contexts orders may capture notions of containment or specialization. Abstractly, this type of order amounts to the subset relation, e.g., "Pediatricians are physicians," and "Circles are merely special-case ellipses."
So again - an order can be defined that makes [1 0] larger than [0 1] - but it does not apply to tha max function
No - exactly max does not work for vectors
I see, yes, by "max doesn't use it" I meant: there is a defined order for vectors and max doesn't use it, and since max doesn't use the defined order for vectors, it doesn't work on vectors
Fine - I know that you can define orderings and partial orderings, but that was not my point here
no idea what your point is, I was just correcting a specific part of what you said, that there is no ordering of vectors defined, which as demonstrated by both compare and sort there is
Like reading out of context?
@jakob.riishede.moller many clojure functions return identity for a single arg without consuming it or checking its validity in any way
user=> (conj :a)
:a
this is useful for cases where you would reduce
across an input collection and need a sensible base case
Is [1 2 3] a sensible base case for a function that computes the maximum?
identity is
and identity of [1 2 3] is [1 2 3]
it works accidentally, whether clojure should eagerly reject invalid inputs is a ship that has sailed already
Well, if at least there was consistency, so that (+ [1 2 3]) returned [1 2 3]?
I agree that the inconsistency is annoying, I doubt there's an easy way out. That said I find clojure generally more consistent than most languages I've used.
Pragmatically, I think it's better to avoid invalid inputs (knowing you can't count on being saved from them by the compiler or the runtime). I have my own pet peeves (eg. merge
accidentally working, sometimes, on things that are not hash-maps)
or (Math/PI) working in the place of Math/PI (despite not being an invocation)
Well - thank you @noisesmith - at least: now i know 👍
Are there any libs or examples of neat ways of interacting with nav-able structures at a REPL
REBL works with Cognitect's AWS lib, dirs/files, data for charting, Java class hierarchies, jdbc data, etc
@lilactown next.jdbc
produces datafy
able/`nav`able result sets by default from execute!
and execute-one!
I wasn’t clear enough. I am not looking for examples of datafy
and nav
, and I know about REBL. I’m wondering if anyone has explored a more ergonomic way of interacting with datafy/nav directly at a REPL. Sort of like https://github.com/eggsyntax/datawalk
(preferably that you could evaluate in a buffer though, so datawalk doesn’t fit exactly what I’d like)
I guess the “semi-interactive” version of datawalk is basically what I’m thinking of
you can totally make something like datawalk for nav, but then you'd be re-building REBL @lilactown
• doesn’t work in CLJS (which is where I actually want to use this right now) • have to leave my editor to use it
You might already know about it, but shadow-cljs has a an "inspector" which is quite handy!
I do know that. like I said, there’s already a purpose built external devtool for this. I specifically want something I can use in my editor / REPL
for my use case, there’s already a purpose built set of devtools for visualizing the objects I want to datafy and nav and I’m interested in building some utilities to interact with them at the REPL
I was hoping I could implement some wrappers around it with datafy + nav and call it a day 😉 but looks like I’d have to build it myself anyway
thheller’s inspector looks awesome but, again, there is already an excellent external devtool for inspecting this data; I specifically want something that works at a REPL. I have my answer, which is, this does not exist yet as far as we know 😄
I don't think you can get very far if you constrain yourself to a text interface
as long as you can assume no background thread is trying to print, you could have a curses UI inspector
not sure if it would be worth the trouble to implement...
oh, there is a guide: https://clojure.org/guides/repl/data_visualization_at_the_repl
I'm trying look at the current state and props of a react component instance without leaving my editor
It's simply walking the react fiber tree and finding where the element type equals the component I want to inspect
But react fibers are opaque data (to CLJS) so I thought I could buy myself some time and effort and use datafy/nav. But datafy/nav is too raw to really be usable at the REPL for that
This code:
(defn- grant->pin [grant]
{:id (:id grant)
:amount_recommended (:amount_recommended grant)
:organization_name (:name grant)})
(defn aggregate-pin-data [data]
(-> data
(get-in [:records :grant_request])
#(map grant->pin %)))
is throwing:
class clojure.lang.Symbol cannot be cast to class clojure.lang.IPersistentVector (clojure.lang.Symbol and clojure.lang.IPersistentVector are in unnamed module of loader 'app')
Which symbol is it trying to cast to a vector? Seems to be complaining about the #(map ...)
lambda but beyond that I'm a bit lost...(defn aggregate-pin-data [data]
(-> data
(get-in [:records :grant_request])
(#(map grant->pin %))))
I could've sworn I've passed lambdas like that to ->
, does this not work at all? Or only in specific cases?
@ctamayo it helps to look at the macroexpansion of the ->
form
@noisesmith I should've thought of that 😛
user=> (macroexpand '(-> x #(+ % %)))
(fn* x [p1__224#] (+ p1__224# p1__224#))
notice how x
becomes the name of the fn, and doesn't appear in the body at all
here's how the (()) hack fixed it:
user=> (macroexpand '(-> x (#(+ % %))))
((fn* [p1__228#] (+ p1__228# p1__228#)) x)
and agreed with @ghadi, it's cleaner not to try to wrap it like thatuse a let, or arguably (-> x (f y) (->> (map g)))
but even this is controversial
->> / as-> etc. are intentionally designed so that they can nest inside ->
fwiw, but opinions about actually doing so are mixed
OK poe's law definitely got me on that one
Without threading it's pretty simple.
(defn aggregate-pin-data [data]
(map grant->pin
(get-in [:records :grant_request] data)))
if you're not using randomcorp's thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang, you're missing out: https://github.com/randomcorp/thread-first-thread-last-backwards-question-mark-as-arrow-cond-arrow-bang Also check out the video: https://youtu.be/jlPaby7suOc?t=699