This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-08
Channels
- # announcements (43)
- # architecture (4)
- # beginners (115)
- # calva (6)
- # cider (4)
- # circleci (4)
- # clara (3)
- # clj-kondo (6)
- # cljs-dev (10)
- # cljsrn (1)
- # clojars (1)
- # clojure (108)
- # clojure-boston (1)
- # clojure-dev (4)
- # clojure-europe (5)
- # clojure-italy (6)
- # clojure-nl (13)
- # clojure-uk (17)
- # clojurescript (47)
- # core-async (2)
- # cursive (13)
- # data-science (1)
- # datavis (15)
- # datomic (12)
- # graphql (5)
- # juxt (10)
- # kaocha (20)
- # lumo (1)
- # off-topic (27)
- # pedestal (4)
- # reitit (2)
- # shadow-cljs (115)
- # spacemacs (4)
- # sql (74)
- # tools-deps (79)
- # vim (15)
- # xtdb (2)
maybe this answers the question
finops-recon.run=> (try (throw (ex-info "foo" {:a 42})) (catch clojure.lang.IExceptionInfo e (:a (ex-data e))))
Execution error (VerifyError) at java.lang.Class/getDeclaredConstructors0 (Class.java:-2).
Catch type is not a subclass of Throwable in exception handler 27
Exception Details:
Location:
finops_recon/run$eval23242.invokeStatic()Ljava/lang/Object; @27: astore_1
Reason:
Type 'clojure/lang/IExceptionInfo' (constant pool 61) is not assignable to 'java/lang/Throwable'
as opposed to
finops-recon.run=> (try (throw (ex-info "foo" {:a 42})) (catch clojure.lang.ExceptionInfo e (:a (ex-data e))))
42
I've just put together a draft PR updating s3-wagon-private to use password instead of passphrase: https://github.com/s3-wagon-private/s3-wagon-private/pull/74. Feedback very welcome
If you have any other complaints or breaking changes you'd like to make to s3-wagon-private, now would be a good time to suggest them
Does a transducer exist like map
but passes the previous result (or initialization) of the map fn into the current map fn?
I could probably make one but this seems like it would be a solved problem
@caleb.macdonaldblack Wouldn't that just be reduce
?
No I need collection back. I'm thinking reductions
actually
I think reductions
is exactly what I need
Actually no? I don't think reductions is a transducer
Check out cgrand/xforms you'll end up there if you're doing transducers, there's a reductions implementation
Yeah, I think you'll have to write your own stateful transducer for that use case...
This is what I ended up with. An improvement would be to have the init optional like reduce
but I don't need that for my use case
I don't plan on using this transducer this way with the +
function. I know there are better ways to do that
I actually need this to calculate battery charge and discharge over time
Feels a bit weird to have the init
value passed like that rather how it is with transduce
, for example. I'd consider having (let [init (rf) prev (volatile! init)] (fn ([] init) (...) ...))
if that works for you?
Although that doesn't quite match how transduce
works either I guess.
Is your feedback regarding the usecase where an init value is not provided and the transducer instead uses the first step value?
@caleb.macdonaldblack It's mostly an unease about how/where the init value is provided for a transducer I think... and I'm not sure what the right answer is.
What would happen if you tried to use your transducer above with transduce
, which provides its own init value, for example?
The initialization value for transduce is passed into the reducing function right?
I guess my transducer behaves more like map but with the previous value. Perhaps reductions-xform
is not the best name
reductions can't really be an xform, it has to be a "reduce" (something that runs a reduce like loop), because if you make it an xform you end up with this weird circular thing
So the init value for reductions-xform
is the first value to use the the prev
result to kick things off. When reducing this collection (possibly with transduce
) the init value is used differently and used as the initital value to reduce the collection to a single value.
but yeah, not a great name
actually idk. The reductions
core function behaves this way
I'm sorry if i'm getting confused with terminology. This is a stateful transducer.
Similar to partition-all
your reductions-xform ends up basically double reducing, once with the function you pass to it, and once with the actual reducing function (which builds the seq for eductions, and is + in your transduce snippet)
In the snippet of code, I was demonstrating that It can be used with transduce
. However the way I've used it is in the example not particularly useful
you don't get a sequence of values that are from the reduction steps of the reducing function
for transducers the reducing function is the thing building the result, so having a result that is a collection of the output of that doesn't work, so reductions-xform might be the closest you can get
Ah okay I see what you mean now
if tools.deps supported npm deps, maybe this would also be useful for planck/plk which already can resolve deps using tools.deps
is there an extension for transit json files that is common? I personally have used .transit.json
Anyone here have experience with Simulant? With notes on what to look out for? https://www.youtube.com/watch?v=N5HyVUPuU0E is very compelling
I did find that useful yes: https://juxt.pro/blog/posts/simulant-01-why.html
@U9E8C7QRJ I've used it a long time ago. At the time I wasn't ready (i think). If you want to get the best out of it you need to structure your application/problem in a certain way so that it's experiments are repeatable (e.g. what is the influence of time or random number generation). Most applications aren't build with seedable random number generation or time manipulation in mind. I think the consequence is that you can only do useful tests around a set of core functions, which is not the same IMO
hi everyone. I am newbie in clojure. I want to know how to halt future in clojure from executing functions before finishing future's processing?
There is future-cancel
: https://clojuredocs.org/clojure.core/future-cancel
Dont want to cancel future, just to halt future from executing some dependancy functions before future's processing.
So basically you want to wait for another condition to happen?
I was a bit surprised (although not sure why 🙂 ) that (set! *warn-on-reflection* true)
doesn't propagate to other threads (unless it's something like future
):
(set! *warn-on-reflection* true)
true
user> (future (println *warn-on-reflection*))
true
(doto (Thread. #(println *warn-on-reflection*)) .start)
false
(.start (Thread. (bound-fn [] (println *warn-on-reflection*))))
Reflection warning, *cider-repl codescene-enterprise-project/empear-enterprise:localhost:58237(clj)*:451:15 - call to java.lang.Thread ctor can't be resolved.
true
Is there a way how to apply it globally to see all warnings even when the code is running in another thread?and a related one: is there any real difference between bound-fn and binding-conveyor-fn ?
I tried setting the clojure.compile.warn-on-reflection
system property in lein's project.clj but got nil as a result 😮
:jvm-opts ["-Dclojure.compile.warn-on-reflection=true"]
# run the repl
*warn-on-reflection*
nil
isn't warn-on-reflection a compile time thing anyways ? do you do compilation in separate threads ?
if using Lein, this is the proper setup https://github.com/technomancy/leiningen/blob/f39bdb6ac4b998577d0c0c4b50cfdbc14cb06f55/sample.project.clj#L285
@U13RRNF2M I guess code is compiled "on the fly" (when it's loaded/required) - with that in mind I do "compilation" in separate threads (just running a big chunk of my code in a separate thread)
So I was a bit puzzled when the things actually get compiled and now I can see that all the code (required namespaces) is actually compiled when the app is started (at least for the lein repl
execution path) not "on demand" when the actual code is invoked - and all that compiled code is stored in memory, not in the class files in the target
dir (only the AOTed main class is stored there).
So when I use :global-vars {*warn-on-reflection* true
as @U45T93RA6 suggested I can see that it's properly set and visible even in new threads.
However, I'm still puzzled why I don't see reflection warnings in my code during the startup procedure although there are clearly some (they are reported by the lein check
command). Perhaps the compilation happens before the var is set?
if you have AOT configured for development, I'd disable it and clear target/
. It tends to cache things, which is undesirable for development.
> I'm still puzzled why I don't see reflection warnings in my code during the startup procedure
your project's code isn't necessarily comprehensively required at startup. lein test
and lein check
do that , but not lein repl
. Something like (clojure.tools.namespace.repl/refresh)
is more certain to require
all your code upfront, therefore giving you the warnings you seek
We only have main
ns AOTed for development.
I tried cleaning target before but didn't seem to have any effect.
I actually modified the compiler to print a message every time ObjExpr#compile is called and it seems that pretty much all my code is compiled (at least as far as I can tell from the limited debug info I got).
E.g. one of my namespaces contains a reflection warning - I actually started the app and invoked the use case where the code is called (therefore it had to be compiled at some point - during the startup or later) but haven't seen any reflection warning in the console.
> We only have main
ns AOTed for development
why? (it wouldn't surprise me if it transitively compiled more stuff)
>I tried cleaning target before but didn't seem to have any effect.
you can always rm
.
> aven't seen any reflection warning in the console.
but are you using refresh
? else you have no warrantee that all your code has been require
d
The main ns is AOT-compiled because it contains the main
method.
find target/classes
gives me just a list of few classes all related to the main ns.
I tried lein clean
before and now rm -rf target
too -> same result.
I don't use refresh
(doesn't work on our project). I'm pretty sure the code has to be compiled at some point though because I actually invoke the code path by triggering the use case in the UI which calls the code containing a reflection call
> The main ns is AOT-compiled because it contains the main
method.
These are unrelated concerns in principle - you can run lein run -m your.namespace
and your.namespace
's main method will be run - no AOT involved at all.
Could as well be. Also I'd make sure (refresh)
can work. Solving both could unmask some issues in your project
The refresh
issue might be related to the AOT compiled main ns - I'll look at that; thanks for pointing that out!
Perfect, refresh
works now!
Although I still don't see the warnings if I don't use refresh
, this is much bigger win for me 🙂
Thanks @U45T93RA6 a lot for your help!
codox is probably most common
oh, from specs
autodoc does that but it's a pain to use
example output: http://clojure.github.io/java.jdbc/#clojure.java.jdbc.spec
thanks @alexmiller. Spec doesn’t support docstrings, right?
Basically my use case is that I’m creating an import/export functionality for my app, and now I’m writing up documentation for the format (which is EDN)
I could probably just post the raw specs, but might be a little dense for people unfamiliar with spec/edn
if you want the autodoc code that formats specs it's here: https://github.com/tomfaulhaber/autodoc/blob/master/src/autodoc/build_html.clj#L407-L447
there's some next level formatting/printing in there, which is probably not surprising given that Tom both wrote the cl-format/pprint stuff in Clojure and autodoc
what is the canonical way to do something like this in clojure? https://reference.wolfram.com/language/ref/NestWhile.html
that's precisely it, iterate and take-while
@henri.schmidt I think this demonstrates chunking doesn't happen
user=> (let [calculated (take 2 (iterate #(doto (inc %) println) 0))] (dorun calculated) calculated)
1
(0 1)
dorun realizes the entire thing eagerly, only the 1 println happens (the first element is the non-calculated init)
without the let / dorun you get a messy output mixing prints with the data
also the version where each step sees all results so far can be done easily with reduce and reduced, or loop
user=> (reduce (fn [els e] (if (> (count els) 10) (reduced els) (conj els e))) [] (iterate inc 0))
[0 1 2 3 4 5 6 7 8 9 10]
https://clojure.atlassian.net/browse/CLJ-1906 may also be relevant
Hi, I need some help with lacinia