This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-07
Channels
- # beginners (166)
- # cider (6)
- # cljs-dev (12)
- # cljsrn (64)
- # clojure (71)
- # clojure-chicago (1)
- # clojure-spec (14)
- # clojure-uk (2)
- # clojurescript (25)
- # datomic (2)
- # docs (1)
- # duct (1)
- # emacs (4)
- # fulcro (5)
- # graphql (3)
- # java (46)
- # mount (5)
- # off-topic (29)
- # onyx (1)
- # portkey (10)
- # re-frame (12)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (1)
- # specter (4)
- # vim (2)
Other than a for
, how would I make this kind of nested mapping more elegant to look at?
(defn OpenSubtitles-parse [file-path]
(let [root (-> file-path xml-reader zip/xml-zip)]
{:documents
(map
(fn [el]
(map
(fn [el] (map zip-xml/text (zip-xml/xml-> el :w)))
(zip-xml/xml-> el :s)))
(zip-xml/xml-> root :document))}))
By using threading macros
you might look at something like specter or a lense library, which would let you expression the transform in a more succinct way (not 100% sure about that)
This is the first time I'm using zip-xml, (or clojure's zippers at all), and it kind of begs something on top like specter, as it is kind of hard to read after being hacked together
Small humorous rant: 4 hours learning how to process huge XML files with clojure...
Any idea why xml-zip
is part of clojure.zip
and not clojure.data.zip.xml
? my ensuing code using xml zippers is barely readable in hindsight.
I have found https://github.com/clojuredocs/guides/blob/master/articles/tutorials/parsing_xml_with_zippers.md at par with Scala API π
@matan I sympathize. I've written just one XML parser with zippers and it was a mind-bending exercise. I still find the code fairly impenetrable.
@seancorfield any good game-plan for the next time around? I guess you don't parse XML much.. thanks for the sympathy anyway π
I try to avoid parsing XML at all costs π
I've never found a really elegant solution, in any technology.
If you're just looking for specific parts of an XML document, maybe Enlive would help? Since then you could use selector syntax to get at the parts you wanted...
But if you're trying to turn entire XML documents into data structures, there's not going to help you π
With specter, is there an easy way to reference another path in a transform?
paths are first-class, so you can do:
(def your-path
(path ALL ALL :something))
(transform your-path f thing)
; combine many
(transform [:thing your-path ALL] f thing)
@matan I can recommend giving odin a spin, https://github.com/halgari/odin
@matan Fiddling with my vim plugin & burning time on slack, what else is there in life?
One day you will no longer be able to code, and it will all look more towards meaningless to you in hindsight, if you didn't leave time to do some other things
I'm kidding, don't worry. I very much appreciate that I need to take real time. I've barely touched my laptop this week, I spent 2 days in disneyland, and a bunch of time around that travelling there & back. I'm currently just killing some time waiting for my SO to get ready. I am trying to find new hobbies, learning Esperanto has been interesting.
For me, getting used to clojure syntax was enough language learning π it has been more enticing than useful, as my coding velocity and productivity didn't experience a real surge switching to clojure, it just felt "pure" in a way
Me too. But productivity has not gone up. I think mainly to several factors: β’ nils v.s. truthiness inconsistent in the language core API β’ obscure to read code when using transducers, which are needed for stream processing and processing huge files β’ chasing data shapes when refactoring code These all mean mediocre speed and productivity for me, so far. Even though I've become somewhat of an ace with functional programming. Community support is good though.
How do I rewrite groovy -> clojure the following two lines ? groovy: https://github.com/dkandalov/live-plugin/blob/master/src/plugin-util-groovy/liveplugin/implementation/Threads.groovy#L51-L52 the problem is that it is doing something with an ABSTRACT nested class, defined: https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/progress/Task.java#L241-L244 I have already tried: ` (com.intellij.openapi.progress.Task$Modal. nil "string" true) ` I suspect the reason this is not working yet is because this is an abstract class, and I somehow have to override the function. Advice ?
@qqq have a look at https://clojuredocs.org/clojure.core/proxy
Given clojure code is data and it is homoiconic and all of that, where are the code refactoring libraries for clojure hiding? π I seem to hand-refactor too much these days... is there anything notable out there, for refactoring moves of sorts? I'm using proto-repl as my editor BTW, but wouldn't care going command-line for it π I've only heard of slamhound, which does something very specific (I think).
what's an idiomatic way to conditionally cache a result of a function call, say depending on an environment? it feels like a use case for delay but my every attempt at creating condition seems to produce some code smell. my best so far is to create a get-fn that either invokes the function or derefs the delay, but I expect there's a better construct and/or ready-made function for it, just haven't found it
@kaosko you are looking for memoize
π https://clojuredocs.org/clojure.core/memoize
if you need more flexible caching (with eviction etc) take a look at https://github.com/clojure/core.memoize
or if you need enterprise-grade π https://github.com/ben-manes/caffeine
I love these names, caffeine has never improved my memoization capability
@lockdown- If often indicates that the function is a primitive variant often meant to be used by a macro, or for use in building a non-starred version.
(Reading your question again, @lockdown- I see I misread and thought you were referring to a star at the end of a functionβs name. I donβt know what a star at the end of a parameter name might indicate.)
yes, was referring to something like https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/try - but your answer taught something new anyway π
Hi all, I've just cloned this git repo: https://github.com/wkf/hawk
I'm trying to run lein repl
and then (in-ns 'hawk.core)
but the directory structure is such that the .clj files are under src/main/clojure/hawk
. I am guessing the structure is different to what I'm used to due to Java being in the repo too. Does anyone have any idea of how I can get to the hawk.core ns
please?
@schmee thanks I did take a look at memoize. I guess my issue was more with caching conditionally, which memoize doesn't seem to solve any better
hmm for conditional caching well I guess I could do (cond-> (get-fn) cache? memoize), that looks pretty enough
@kaosko Maybe look at core.cache
or core.memoize
and the examples in the docs around those? They rely on a through
function to encapsulate the conditional logic.
(swap! my-cache core.cache/through-cache :some-key (fn [k] (code-to-produce-value k)))
@seancorfield thanks, yeah core.cache is good with proper eviction but have to stop overthinking this, especially since there was really no other reason but to try to make it prettier π
Ah, I hadn't scrolled far enough back to see the earlier comments about core.memoize
, sorry! @kaosko