Fork me on GitHub

if you have something like (into [] a-transducer (range n)) - does the range sequence gets created and cached here?


there is no seq


range returns a thing that both implements Iterable and IReduce, both of which have custom fast paths when processed via reduce, which into does


gotcha thanks, was just learning about reducible collections


looking at the source, in these case is using transduce instead of reduce but yeah, same concept

Alex Miller (Clojure team)02:11:32

and range doesn’t actually cache anything


@alexmiller if you do (map foo (range n)) - the values of range don't get stored in memory?

Alex Miller (Clojure team)02:11:37

that’s not the code you have above

Alex Miller (Clojure team)02:11:50

and what happens is much different


oh ok, though you were saying it in general

Alex Miller (Clojure team)02:11:13

when using a range as a reducible (as with into), the whole thing just boils down to a single loop over the data and no values are cached in memory

Alex Miller (Clojure team)02:11:08

even when used as a seq, it builds chunks that store only the start/step/count values, not the actual data values


neat, so something not to worry about to much


what makes a collection reducible? what are properties must it satisfy?

Alex Miller (Clojure team)02:11:03

and has a reduce method

Alex Miller (Clojure team)02:11:07

the into example above is primarily running this loop

Alex Miller (Clojure team)02:11:33

where f is the transducer

Alex Miller (Clojure team)03:11:38

this is not the only path to being reducible, but it’s the fastest

Alex Miller (Clojure team)03:11:48

you can also participate in the CollReduce protocol


for building non-caching reducible things on the fly, there's also eduction


so basically it needs to know how to perform a reduce on itself

Alex Miller (Clojure team)03:11:26

vectors and maps also know how to do this


in the case of long range

Alex Miller (Clojure team)03:11:50

and the results of cycle, iterate, repeat


is there a predicate for reducibles?


(doc reducible?) returned nil 😉


you can use instance? though

Alex Miller (Clojure team)03:11:59

#(or (instance? clojure.lang.IReduceInit %) (satisfies? clojure.core.protocols/CollReduce %))


@alexmiller that reminds me, has there ever been any consideration of a for variant for producing a similar reducible/iterable? I remember poking around a while back thinking there'd be one. I figure it just doesn't come up enough as an optimization to be necessary, particularly since you can usually achieve the same thing with eduction, iterate, etc, but while we're talking about it....

Alex Miller (Clojure team)03:11:09

I’m not sure that makes sense

Alex Miller (Clojure team)03:11:58

reducible gets it power by eagerly consuming the source, so doesn’t make sense to make one reducible from another


just curious!


does the sequence fn just does the opposite of a transduce?

Alex Miller (Clojure team)03:11:26

not sure what that would mean, but no :)


heh, let me reread this

Alex Miller (Clojure team)03:11:34

the sequence function, when used with a transducer makes an incrementally computed sequence


mostly it's just there so you can generate a lazy-sequence by composing transducer functions (map, filter, take, etc) without having to use them as lazy sequence functions - saves the overhead of the intermediate sequences

Alex Miller (Clojure team)03:11:07

there are some differences from lazy sequences as each intermediate step is fully computed

Alex Miller (Clojure team)03:11:19

transducers are a push model, not a pull model

Alex Miller (Clojure team)03:11:47

so for example, lazy sequences can compute infinite intermediate sequences and you can use as much of that as you like

Alex Miller (Clojure team)03:11:10

but sequence with a transducer would work forever producing the intermediate step

Alex Miller (Clojure team)03:11:20

most commonly this comes up with mapcat


oh, yeah, ike if you had a filter that's never satisfied it would run forever trying to get to a value that satisfies the filter even if you only try and get a single item from it

Alex Miller (Clojure team)03:11:28

well, that may be true of both


hahaha yeah I realized that after I said it, whoops

Alex Miller (Clojure team)03:11:08

like (take 2 (mapcat #(repeat 1000 %) (range 5))) only needs to produce 2 values


actually, that explains why the core transducer functions don't just do, like, ([pred col] (sequence (filter pred) col)) for the lazy-seq-producing form, instead using lazy-seq directly

Alex Miller (Clojure team)03:11:32

but (into [] (comp (mapcat #(repeat 1000 %)) (take 2)) (range 5)) will produce 1000 values and give you 2


@alexmiller actually, thinking about this further, are you sure this is the case? take short-circuits the whole pipeline (even to the point of preventing chunked loading when using sequence) - (into [] (comp (mapcat #(repeat 1000 %)) (map #(do (println %) %)) (take 2)) (range 5)) only prints 2 lines, for example, as does (sequence (comp (mapcat #(repeat 1000 %)) (map #(do (println %) %)) (take 2)) (range 5))


(into [] (comp (mapcat (fn [v] (iterate #(do (println %) %) v))) (take 2)) (range 5)) also successfully terminates despite the infinite iteration in the mapcat, printing 1 line


My read on it is that while transducers are push-based, the fact that it's all driven by a reductio pipeline lets you nevertheless control it via reduced, avoiding realizing values that will never be used except in unavoidable situations that also apply to lazy sequences. At least, I can't think of one that would apply to a transducer pipeline + sequence but not a lazy-seq


which I always do when I write my own because I am a lazy fool

Alex Miller (Clojure team)03:11:46

both seqs and transducers have their place


oh sure. I just mean, when I write my own custom transforms, I like to follow teh same pattern as core and make them work either as transducers or sequence functions based on arity. but I usually just take the shortcut of using sequence. this conversation has me reconsidering that, though

Alex Miller (Clojure team)03:11:39

yeah, I wouldn’t do that

Alex Miller (Clojure team)03:11:59

they really are different


yeah, I see why it's a bad idea now that you point out the effects of the push behavior. thanks


there's likely also more overhead for the same result


@alexmiller your into and concat example was to demonstrate what the sequence fn does with a transducer? that it fully computes intermediate values


or as you better said, each intermediate step is fully computed


finding a use case for sequence, is like when you want a lazy result of intermediate steps

Alex Miller (Clojure team)03:11:30

that use case is imo small


yeah, I guess is not used much in practice, or at least can think of any right now.


Has anyone here successfully deployed a “create-react-app” app with ring? I’m having trouble to work with registerServiceWorker.js, it says on the console log:

No internet connection found. App is running in offline mode.


I’m using ring.middleware.resource/wrap-resource and it works


Is state of the art for getting started with "write a reddit bot in clojure" ?


the github link doesn't work, and the author doesn't seem to appear either


Hi. I'm trying to write a test with cljs.test. I want to have all the names from my main module right available in the test module. Without prefixes or explicit enumeration. Can I do that?


You mean without requiring them?


Basically (:use [app.main :only [multiply]]) works while (:use [app.main]). While the docs say that both are correct.


@orend Any way that works.


(:require [app.main :refer :all])


I believe :use is discouraged these days.


Still doesn't compile Only :as, :refer and :rename options supported in :require / :require-macros;


Wrong message, real one > Don't know how to create ISeq from: clojure.lang.Keyword


Can you paste your entire ns form?


did clojurescript drop support for :all? am i misremembering that?


Oh, is this ClojureScript?


drop or possibly never support?


cljs.test was mentioned


yep. Does it handle ns differently?


Ah, yes. :all is not available in ClojureScript.


No idea why though.


Wow. Didn't expect incompatibility on this level. Thanks!


It most likely is an issue with bundle size — but you could ask on #clojurescript for details.


As a “workaround”, you could do (:require [app.main :as a]) and use a/foo, a/bar. It’s an extra two characters on every occurrence, so just a little bit more onerous than the naked case.


I agree though that sometimes for tests it’s nice to be able to just bring everything in.


@masta please consider unpinning your message.


Yeah, it’s discouraged in this Slack, only for admins to use. Thanks 🙂


How do you guys do Profile Clojure projects? I have tried JVisualVM bur it gives me some cryptic info. Please advice.


Can you share some more info? What’s the cryptic info look like, what are you trying to measure?

Audrius14:11:32 This is what I mean. Nothing resembles my actual code.


Are you using code from the namespaces importer.integrity and clj_xml_validation?


Meaning, is your code in those two namespaces?


I’m not an expert on this, nor do I know if there’s a better way to do profiling on Clojure, but with a little effort this output is readable: clj_xml_validation.core$validator_from_schemas.invokeStatic is equivalent to a call to function (clj-xml-validation.core/validator-from-schemas ...)


importer.integrity$differing_contexts_for_global_ids$iter_4304__4308$fn__4309$fn__4314.invoke is a little bit trickier, as it probably involves some anonumous function inside importer.integrity/differing-contexts-for-global-ids.


The top one, clojure.lang.Util.equiv is the = function, IIUC.


thanks I will have a closer look!


Do you know any other tools?


that might help you out a bit


and - don’t forget you can (and should) name functions too eg, (fn foo [a b] (+ a b))


which will help a ton for those anons


The hot spots can be confusing because you're not seeing a tree of method calls. Look in the Threads tab or Thread CPU time (can't remember if both of them have the method call tree).


Another issue which I have run into with profiling in Clojure is that laziness can give you misleading results. i.e. If I construct a large lazy sequence in an inefficient manner, then I will not see the CPU spike at construction time (where the problem is), but whenever the list is actually evaluated and used


Hi guys, ever since I've upgraded from AWS Java SDK V1 to V2, I've been getting about 80 lines of warnings about version ranges. From reading [1] I understand that this issue is not going to be resolved soon, but is there anything I can do to suppress these messages for just these dependencies? [1]