This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-17
Channels
- # announcements (4)
- # aws (17)
- # beginners (108)
- # calva (2)
- # clojure (164)
- # clojure-austin (1)
- # clojure-europe (3)
- # clojure-italy (1)
- # clojure-nl (17)
- # clojure-uk (98)
- # clojurescript (31)
- # code-reviews (1)
- # cursive (23)
- # data-science (1)
- # dirac (6)
- # emacs (21)
- # figwheel-main (1)
- # fulcro (53)
- # graphql (2)
- # hoplon (1)
- # lein-figwheel (1)
- # leiningen (2)
- # lumo (21)
- # off-topic (118)
- # onyx (4)
- # pathom (59)
- # pedestal (2)
- # planck (3)
- # reagent (47)
- # reitit (2)
- # shadow-cljs (258)
- # spacemacs (3)
- # sql (10)
- # tools-deps (37)
I have in coming datastructures for requests like this
[{(ucv.ui.root.signon/login {:email "", :password "letmein"})
[:session-key :logged-in? :user-id :firm-id :pos/id :user/id :firm/id]} :com.wsscode.pathom/trace]
And I want to log them, but omit any whitelisted keys (like :password
), but otherwise log the datastructure completely as is (don’t want to change vectors to lists or anything). What the recommended way of doing that?I tried clojure.walk/poswalk
but even with identity
that changes the datastructure
oh wait no, i forgot to prevent the list from being treated as code
so, seems like postwalk can work, is that the recommended approach for something like this?
just logging with timbre
yeah to remove the :password field in an arbitrarily nested structure postwalk is your best bet
postwalk
should do well. If you want to preserve the datastructure though (i.e, not everything should be coerced to seqs which print as lists) check out the library specter
. Code for things like this also ends up being faster and less ceremonious.
I want to write a clojure function in java, and that function may throw an exception that is unknown at compile time. in clojure I can throw anything, anywhere :
(fn [error] (throw error))
So clearly the JVM bytecode allows this and it does the expected thing at runtime. But if I try to do that in java, javac
gives the finger :
new AFn() {
public Object invoke(Object error) {
throw (Throwable) error;
}
};
unreported exception java.lang.Throwable; must be caught or declared to be thrown
is there a compiler or language trick to make javac
happy there ?found my answer https://stackoverflow.com/questions/4519557/is-there-a-way-to-throw-an-exception-without-adding-the-throws-declaration
You can find various utilities Clojure uses for this in clojure.lang.Util, like the sneakyThrow() method.
With clojure.tools.reader, how do I set the “current ns” when reading auto-namespaced keywords?
(binding [r/*alias-map* {? 'foo}] (read-expressions "(ns foo) #::{:b 1}"))
that works:
(binding [*ns* (create-ns 'foo)
r/*alias-map* {'foo 'foo}] (read-expressions "(ns foo) #::{:b 1}"))
but I’ve no idea if that’s how it should workconsider "(ns foo (:use bar)) (foo) #::{:b 1}"
with (ns bar) (defn foo [] (in-ns 'bar))
Hello guys
what is the best way to override protected java method ?
for example:
i would like to write this piece of java in clojure
there was also once a discussion about this on jira, but it's gathering dust: https://dev.clojure.org/jira/browse/CLJ-1255
Well aware of it, hoping to consider for 1.11 when we get there
how useful are code reloading libraries like Component, Mount or Integrant? I worry that I'm diving into using a workflow I don't really need.
as soon as you have resources that need to be initialized and restarted (database connection pools, HTTP server, job scheduler etc), it starts to make sense to use this pattern. I found Component to have too much bureaucracy and mount to be too “magical”, so these days I feel that integrant is a very good middle way
just roll your own version of component, it's very easy, focusing just on getting a minimal system map. i've found it useful in all my projects. it helps things not to get out of hand, and makes testing simpler
you probably can't just rely on people's opinions, because like this thread, some people will say don't use them, others will swear by them. 🙂
at the moment I'm defining start
and stop
functions in a top level namespace, and putting stuff like my http server into atoms using defonce
but I guess you have to start and stop them in a particular order, right?
I can see where there'd be a tipping point in system size, and it's just simpler to define integrant keys
You could start with just an atom holding your database connection pool - then go with one of those libraries when you need a second atom and dependencies between them.
Just throwing this out there as a GUI alternative. I'm slow, still learning Clojure, time-constrained but I think a productive exercise is to translate the guiserver.lsp file written in newlisp to clojure. The actual GUI part is written in Java and spun up separately from a jar and the guiserver.lsp talks to it over a socket. I think it would be a very nice addition as a clojure librsry. If you play with it first in newlisp, you'll find its plenty responsive and complete enough.
Anyone know of something like clojure.core/eduction
except where the input is itself a reducible?
Another way to say it would maybe be “something that could wrap a given reducible with a transducer xform”
(defn less-promises-eduction [xform coll]
(reify clojure.lang.IReduceInit
(reduce [_ f init]
;; NB (completing f) isolates completion of inner rf from outer rf
(transduce xform (completing f) init coll)))
@hiredman Heh, how about that. I assumed from the docstring it needed a coll, and I saw that error when trying it at the repl 🙂
Thanks very much
I have a function that returns a lazy sequence, and I want to lazily concat invocations of this function. So I wanted to use concat
, but I heard that it has performance issues and that each concatenation deepens the call stack. Is there some other way I can achieve this?
For instance if you had a function (get-page n)
and it returns 10 items or nil, and you wanted to return a sequence of items that lazily calls get-page
in the background as needed, what would you do?
and each call has a cost so you don't want to chunked-seq 32 calls at a time
https://dev.clojure.org/jira/browse/CLJ-1906 is a longer exploration of this problem
I heard a couple of people complain about that
the problem with concat occurs when you use it in particular ways, but for example (apply concat (get-pages ...))
is generally safe
And it's not (concat ...seqs...)
it's really (concat page 1 (lazy-seq (concat page2 (lazy-seq (concat page-3...
A sequence of concats on 2 args
but I don't know in advance how many subsequences I need to fetch
I'm not going to load all pages then apply
that defeats the purpose altogether
(apply concat s)
forces the first two elements of s (the first two pages) and then the rest will be forced as you walk the seq
but in general, lazy-seqs are not the best abstraction for io, which is why in my initial proposal on CLJ-1906 linked above I suggested something that just implements IReduceInit
exactly how and when pages are forced if you use lazy-seqs will also depend a lot on where/if you put the (lazy-seq ...)
inside get-page (assuming it has one)
yeah I am aware of that
I think I'll read the discussion in that ticket
https://ce2144dc-f7c9-4f54-8fb6-7321a4c318db.s3.amazonaws.com/reducers.html is a thing I wrote a while ago about using reduce for this kind of thing, it talks about reducers which are kind of old news these days, clojure has grown even more reduce related features since then (transducers, the interfaces Reduce and ReduceInit)
i seem to recall that there was a way to inspect or print out the intermediate values of the threading macros... like an audit or something... does that ring a bell for anyone?
(-> foo (f) (doto println) (g))
is one pattern for a quick hack
How do I add metadata, this doesn't work:
(-> (map (fn [x] ^{:a 1} x) [1 2 3])
first
meta)
;; ==> nil
numbers don't accept metadata, you need a type which supports it
the metadata is implemented as a field on the object that has it, if the object doesn't define the field there's nowhere for metadata to go
it might be more straightforward to use (fn [x] {:a 1 :val x})
and then use (map :val)
at the last step, rather than putting the metadata on the thing, you mix the thing in with the metadata
hey everyone. i noticed that my heap usage according to visualvm has been increasing monotonically since i launched my application in the repl. is there anything going on under the hood that could be contributing to this outside of my application, or do i definitely have a leak somewhere?
the biggest gotcha I can think of is an indefinite lazy-seq where you hold onto a reference to the head
but also it's normal for the jvm gc to let your app usage ramp up indefinitely until some limit is hit - you can test this by specifying a lower max usage
OK, that's normal jvm behavior, it's batching some things for perf reasons
a normal run of a well-behaved app will look like a sawtooth, where garbage slowly accumulates then all goes down at once
so i wonder if i need to keep my maximum steady-state usage to less than the vertical offset of this sawtooth
depends a lot on your app. how much resident memory does the app actually need? how fast does it produce garbage objects? etc. there are a few hundred knobs to turn for GC.
hmm, ok. are there any resources you could point me to in learning to formulate the right questions to ask here?
it's a big topic, probably worth doing some googling. I don't have a canonical resource to point you to.
@gtzogana Folks who are new to the JVM are often shocked by how much memory it takes up but it's a highly tuned platform and its ability to transparently use and release memory is part of what gives it the power it has... In production, we run processes with between 1GB and 4GB max heap typically -- mostly toward the low end of that -- and those are pretty high traffic processes.
(we have multiple, small services in Clojure now -- previously we had a monolithic web app in a different tech on the JVM and it needed 10-15GB of heap to stay high performance)
What kind of tech did you have on the JVM to run the monolith? A web framework? I am just wondering which stack takes 15 GB to run.
CFML. It would run in a lot less, but the best performance was when we cranked the heap up to 15GB, so the GC had plenty of leeway to do its work (we we using the G1 collector so we could minimize pauses and have reliable throughput).
wow, Cold Fusion. I remember that framework. It was just before Rails started gaining traction.
These days CFML has both a commercial implementation (Adobe) and an open source implementation (Lucee). It evolved into a JS-like scripting language that compiles-on-demand to JVM bytecode (like Clojure), with a traditional OO model (unlike JS's prototype stuff), and it supports some metaprogramming, closures, map/filter/reduce etc. And it changed from Cold Fusion to ColdFusion some time in the 90's 🙂 I first encountered it when I worked at Macromedia and they bought Allaire (who created it in '95).
We migrated piecemeal to Clojure -- I wrote a small CFML library that did some classpath "magic" and used Clojure's Java API to require
and call into arbitrary Clojure code:
;; Clojure code
(some.namespace/func arg1 arg2)
// CFML code
clj.some.namespace.func( arg1, arg2 );
🙂Then we rewrote our code from the bottom up, until we had enough built to start spinning off individual Ring/Compojure apps.
I even have an adapter, written in CFML, that can call Ring handlers written in Clojure, and bridges cookies and session management across the two, so we can rewrite our remaining app one controller method at a time 🙂
I know that companies will hire you on the spot for Cold Fusion… because the talent pool is so tiny.
That's how I got hired into my current company -- where I introduced Clojure to replace CFML 🙂
is it a good strategy as one grows in their career? Opposed to working for startups just doing full stack dev?
I'm server side only and I don't like startup / Silicon Valley culture 🙃
Front end stuff is just too annoying for an old dog like me to want to put up with!
ohhh believe me too… JS fatigue is hitting me too. I think JS is driving tons of people nuts.
6 ways… omg wow
I'm so out of touch -- I know only two ways in JS! :rolling_on_the_floor_laughing:
Articles like that are why I detest JavaScript 🙃 (but I now know a lot more about JS than I did before I read that!).
I spent half the day looking for a Javascript function in the codebase… only to find out that some weird function definition was used… so ya… JS is a pain in that regard. I think that’s why so many people love TypeScript.
I was feeling older today too. But a girl cheered me up. She said that us seniors are actually very valuable. The reason we feel like a small group is that the industry is on a 30% growth rate. So you and I started out when the entire workforce was smaller. She pointed out there’s a huge population size skew. My dad always felt like his age was against him. But it’s simply not true. Experience matters a ton in this field. Looking back, I’ve made so many mistakes that only a senior version of me could understand now. For starters… jumping on a technology too soon only to end up using it for six months. Mostly JS tech stuff that keeps changing.
Every GC run, that is, having to loop over objects, identify garbage, and clean it up, takes CPU away from your app
And also will hit your CPU caches and all. Making them cold again for your own computations
That's a typical server workload style. Where it assumes your process is the main thing your OS is running, and thus it's better to maximise all your memory use and trade it for better performance
@gtzogana This is a good overview of the GC options: https://dzone.com/articles/choosing-the-right-gc
It's a bit old, so it's leaving out a new GC coming in Java 11 (https://www.opsian.com/blog/javas-new-zgc-is-very-exciting/)
Is there any concept of inheritance ala common lisp CLOS defclass extending another class and fulfilling its type checks of the parent (particularly for multi method dispatch)? Like, if I have a defrecord Person, and want multi dispatched on class. And want an Employee to extend person defrecord without redundant list of field names in arg vector, and would like a defmethod foo Person to work on an Employee instance
what you are describe is a typical oop type/class hierarchy, which to some degree clojure rejects(while still having to interop with that kind of thing on the java side) as a good way to organize data.
Clojure rejects concrete inheritance