Fork me on GitHub
#clojure
<
2015-08-20
>
axle02:08:47

question about subseq and sorted-maps and efficiency...

axle02:08:57

I have a sorted-set with about 200k integers. I take a subseq of those less than X. The resulting subseq can still be quite large. What I get back is a sequence, but I want it back as a sorted-set.

axle02:08:24

If I use (into (sorted-map) my-sub-seq), doesn't that do an O(n) deep copy of the subsequence into a new sorted-set?

axle02:08:13

sorry, I meant (into (sorted-set) my-sub-seq) ;; sorted-set not sorted-map

Alex Miller (Clojure team)02:08:33

You might want to look at some of the other contrib data structures for this

Alex Miller (Clojure team)02:08:34

I think data.avl gives you log time splitting

cddr03:08:58

some-fn and clojure.data.zip.xml don't play as nicely together as I'd have thought

cddr03:08:30

You can't do (some-fn (tag= :foo) (tag= :bar)) because the function returned by (tag= :foo) always returns a truthy value (i.e. an empty list) even if there's no element "foo"

axle03:08:18

alex, thanks for the heads up about data.avl. Appreciate it!

tsdh10:08:15

@cddr: Indeed. The function returned by tag= does (filter ...) and seems to return the seq of children with the given tag name in one case and just the seq containing the current element in case its tag equals the given tagname in the other case. So it's no predicate at all although the docs say so. The text= and attr= functions do return proper predicates, though. I'd go and file a bug report.

tsdh10:08:57

@cddr: In the meantime, you could probably go with (comp seq (tag= :foo)).

tsdh10:08:32

@cddr: Hah, there's even an issue for that since more than a year: http://dev.clojure.org/jira/browse/DZIP-3

tsdh10:08:23

@cddr: No comments, no confirmation, no nothing. And the last JIRA activity for any issue in that project has been end of 2013. That probably means "fork and fix me" in case you want to use it.

timvisher13:08:58

is (:gen-class) enough or do you need (:gen-class :main true)

timvisher13:08:11

both appear to work, but what’s the difference between them?

chris_johnson14:08:58

@timvisher: I believe, though I don’t have time before standup to go validate my memory, that (:gen-class) forces AOT compilation while adding :main true wires that ns up as the entry point for a JAR

cddr14:08:02

@tsdh It might have been done that way to maximize the library's laziness but I'll throw up a patch and see if I can get some discussion going.

cddr14:08:17

Thanks for finding the existing issue

tsdh14:08:20

@cddr: You're welcome.

timvisher14:08:55

@chris_johnson: Thanks for the input. I have it in my head that I can use an ns with nothing but (:gen-class) in it as the entry point for a jar, but that’s probably untrue. Mental cruft…

timvisher14:08:21

the docs certainly seem to indicate that without :main true the static main function is not generated.

chris_johnson14:08:57

It’s also possible that you can get away with just (:gen-class) with the addition of some sugar in project.clj in the case where you’re using Leiningen

chris_johnson14:08:32

and that adding :main true becomes vital when you start to leave the warm, blanket-like embrace of Tools™

stuartsierra14:08:45

@timvisher: :gen-class defaults to :main true when used in the ns macro.

stuartsierra14:08:03

Since that's the only thing it's used for 99% of the time.

stuartsierra14:08:17

The presence of :gen-class by itself does not trigger AOT-compilation. AOT-compilation is always initiated by calling compile, usually through a build tool.

stuartsierra14:08:30

All the gory details are in the docstrings of the gen-class and ns macros.

timvisher15:08:56

@stuartsierra: ah! that makes much more sense now.

sdegutis16:08:34

Does anyone here have a tl;dr on the benefits of using Transducers rather than just piping seqs with ->>?

spinningtopsofdoom16:08:51

@sdegutis No intermediate datastructures between functions and you can use the same stack of functions in normal clojure code, reducers, and core.async

sdegutis16:08:13

@spinningtopsofdoom: Aren't reducers also normal Clojure code?

spinningtopsofdoom16:08:21

Technically but you need to use the reducer map filter and reduce functions rather then the ones in core

darwin16:08:30

@sdegutis: without transducers, you would have to implement map, filter, and other common functions for each new context (seqs, channels, etc.)

sdegutis16:08:14

Thanks, will do.

darwin16:08:27

@sdegutis: to answer your original question, if you have just seqs you don’t need transducers, you can use map, filter, and other core functions the old way

darwin16:08:23

transducers shine when you want to use some other underlying data structure and don’t want to rewrite whole core library

sdegutis16:08:52

@darwin: Oh so basically this is so Cognitect don't have to rewrite them for channels?

tel17:08:09

Is there a way to export names from an imported namespace without just re-defing them all?

rauh17:08:33

@tel vinyasa.inject and/or potemkin/import-var does that.

rauh17:08:09

You can probably combine it with dir

cddr20:08:04

Should I have to do anything special to get concurrent logging printing without interleaving when I'm using timbre as my logger?

lvh21:08:41

I have a coll with maps that have a :type. How can I get a count per :type? group-by is useful, but is there a map for vals?

lvh21:08:16

or basically is there a shorthand for (zipmap (keys m) (map f (vals m))

potetm21:08:15

I would do (into {} (map (fn [[k v]] [k (f v)]) m). Not shorthand, just different.

potetm21:08:53

That fn could also be (juxt first (comp f second)). Just depends on how you prefer really.

jackjames21:08:24

hmm cool, did not know about frequencies

jackjames21:08:13

(frequencies (map :type [{:type :foo} {:type :bar}]))

jackjames21:08:23

that works, no?