This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-25
Channels
- # admin-announcements (19)
- # alda (73)
- # announcements (1)
- # aws (16)
- # beginners (22)
- # boot (109)
- # cljs-dev (1)
- # clojure (79)
- # clojure-art (3)
- # clojure-czech (2)
- # clojure-russia (233)
- # clojure-sweden (2)
- # clojurescript (161)
- # clojurex (25)
- # core-async (2)
- # cursive (4)
- # datomic (11)
- # editors (17)
- # emacs (3)
- # funcool (4)
- # hoplon (72)
- # ldnclj (29)
- # off-topic (1)
- # om (9)
- # onyx (13)
- # reactive (10)
- # reagent (13)
- # yada (4)
i'm trying to process some XML data and I've used clojure.xml to get something like this - https://gist.github.com/mikos/dea83b5c507eccc93e80 - can anyone point me in the right direction to convert that to a more traditional clojure map structure?
Annoying there's no backtick on the iOS keyboard in slack, unless I'm just missing it
I learned about it here: http://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects
@bhagany: I like Stuart's Clojure Don'ts. The times I typically find myself forcing the activation of lazy sequences is with Criterium benchmarking where you want to make sure you're actually timing some activity. I've had a few momentary dramatic performance improvements because I forgot what I was testing was lazy and it wasn't really measuring any activity.
I keep forgetting about run!
and haven't used it yet. There isn't much on ClojureDocs. Is (run! proc coll)
pretty much the same as (dorun (map f coll))
?
I guess the source speaks for itself:
(defn run!
"Runs the supplied procedure (via reduce), for purposes of side
effects, on successive items in the collection. Returns nil"
{:added "1.7"}
[proc coll]
(reduce #(proc %2) nil coll))
Kind of funny that here's a new "feature" of version 1.7 of Clojure and you go look at it only to discover that it comes down to (reduce #(proc %2) nil coll)
For me it's disappointing and amazing and refreshing and encouraging all at the same time.
Hey! I just learned about empty
. Wish I knew about it yesterday. Now I need to change more code that should have used empty in the first place. Hmm...
I’m trying to use humane-test-output for clojure.test, and I’m not seeing any diff output.
What's a shorter way to say this?
;; original
(into {} (map (fn [[value {:text text}] choices-map]
[value text]) my-choices-map))
;; progress so far
(into {} (for [[value {:text text}] my-choices-map]
[value text]))
;; by <@U0517LEP0>
(into {} (map (fn [[value {text :text}]]
[value text])) my-choices-map)
;; by <@U054D2JUV>
(into {} (map (juxt key (comp :text val)) my-choices-map))
;; by <@U05224H0W>
(reduce-kv #(assoc %1 %2 (:text %3)) {} my-choices-map)
;; by <@U051MTYAB>
(zipmap (keys my-choices-map) (map :text (vals my-choices-map)))
@cfleming: I remember having weird interactions between human-test-output and Cursive. You’ve set up your profile.clj
as well?
@mbertheau: not really shorter but (into {} (map (fn [[value {text :text}]] [value text])) my-choices-map)
uses transducers and may be slightly quicker or more readable
@danielcompton: I’m actually not doing this through Cursive, just normal REPL
I'm assuming you've followed instructions for profile.clj?
@mbertheau: (into {} (map (juxt key (comp :text val))) my-choices-map)
would also work
@mbertheau: (reduce-kv #(assoc %1 %2 (:text %3)) {} my-choices-map)
@mbertheau: (zipmap (keys my-choices-map) (map :text (vals my-choices-map)))
Is there a difference between (filter (constantly true) ...)
and (filter identity …)
?
@martinklepsch: there is if you’re filtering a sequence with a nil in it
right, good point.
I was actually more wondering about it in terms of performance
what's the best way to turn this into a more traditional map? https://gist.github.com/mikos/dea83b5c507eccc93e80
(that's the output from running clojure.xml/parse :))
@mikecarter: do you need the attributes?
is there a standard function or a canonical way to make a "sliding window" transducer, e.g like when you do (partition-all 4 1 coll)
@martinklepsch: some attributes, yeah but i'd be happy with a solution without them for now
@mikecarter: unfortunately I don’t have any definitive answer. last time I worked with xml I came to the conclusion that it’s best to familiarize myself with zippers etc. xml is too different from regular maps I’m afraid. maybe others have different experiences to share.
that's cool, thanks for taking a look @martinklepsch
i have a solution here i think, just not sure it's the most efficient!
its not quite the same thing but I found parsing RSS feeds as XML into structmaps using https://github.com/scsibug/feedparser-clj was very nice. I wonder if you could reuse the concepts there.
thanks @dexter - i'll take a look at that now
I'm looking at this page from JRebel and the name Clojure support. http://zeroturnaround.com/software/jrebel/ What does that mean? Something like a REPL makes a tool like this obsolete right?
@borkdude: I guess it depends on your deployment environment and dependencies? What if your heavily interoperating with Java? Integration with other systems? Test environments for end to end func/non-func testing?
In the enterprise world you’re rarely testing in isolation
I am trying to eval this code in my repl (pasted from changes.md): #?(:clj Double/NaN :cljs js/NaN :default nil) result I get is: CompilerException java.lang.RuntimeException: Conditional read not allowed, compiling:(/tmp/foo.clj:2:5)
where does LEIN_PASSWORD come from in https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L103 ?
on windows windowskey+Pause/Break > Advanced System Settings > Environmental Variables > New...
@harshdeep: It creates a binding for the symbol developer
within the scope of the let
. In other words, as long as you’re within the let
form (i.e. inside the parenthesis surrounding let
), developer
will resolve to ”Alice in Wonderland”
.
When I first started clojure, it was helpful to think of let as an analog of a variable assignment inside of a method. It's not useful to think of things from an imperative language mindset long term, but at first it can be a nice crutch.
Good suggestions. I’ll just add that once you’re comfortable with thinking of let as a series of assignments consider how you would accomplish the same in functional programming if let wasn’t there. You’d define a little inner function with something like a developer parameter, and then immediately call it with the string you want. This is what is meant when folks say “Let is a lambda"
If you are familiar with JavaScript, it is the same idea as
(function(developer) {…}(“Alice in Wonderland”));
At least the sort that I hang with 😉 (and at least in some lisp implementations, it can be written as such if it is not primitive)
I may’ve not placed my thumb precisely on the lisp programmer zeitgeist, but I’d at least encourage the use of the phrase
"The simple, non recursive let expression was defined as being syntactic sugar for the lambda abstraction applied to a term" https://en.wikipedia.org/wiki/Let_expression#Laws_relating_lambda_calculus_and_let_expressions
((fn [x] .... something with x ....) value-for-x) or (let [x value-for-x] ..... something with x ....) are essentially the same thing
hi, I’ve got a compojure-api question. I am trying to have just one end-point return text/html - I have wrapped it in some simple middleware but it seems adamant to return json. Any ideas ?
@shriphani: Are you returins a string from handlers or something else?
@juhoteperi: string
shriphani: Remove :return String
, it tells compojure-api to serialize the result
@juhoteperi: worked perfectly ty. 💯
is there any way to do an alts! in core.async and also get information for when all the channels have been closed?