This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # bangalore-clj (4)
- # beginners (53)
- # boot (7)
- # cider (1)
- # clara (1)
- # cljs-dev (13)
- # clojure (29)
- # clojure-dusseldorf (3)
- # clojure-russia (7)
- # clojure-spec (63)
- # clojure-uk (7)
- # clojurescript (51)
- # css (1)
- # datomic (5)
- # emacs (1)
- # events (1)
- # fulcro (15)
- # hoplon (3)
- # immutant (3)
- # juxt (1)
- # midje (2)
- # off-topic (24)
- # om (1)
- # parinfer (1)
- # portkey (54)
- # re-frame (4)
- # reagent (13)
- # schema (1)
- # shadow-cljs (19)
- # sql (1)
- # testing (37)
- # yada (2)
Having a bit of trouble with my answer to problem 22 (http://www.4clojure.com/problem/22) on 4clojure.. my answer
seems to trip the alarm for
#(reduce + (for [i %] (let [x 1] x)))
countalthough I don't explicitly call it. Is that because
countis being used in the
count. Here’s the source: https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L4576
#(reduce (fn [c _] (inc c)) 0 %)?
there's not much to learn about _ - it's just our preferred name for things we don't use, but as far as clojure is concerned it's just a name
(let [_ 2] (+ _ _)) => 4 - don't write code like that,it just demonstrates that _ is a name convention, not a syntax
I'm using enlive to parse some html page and I came to the point I have this problem:
<div id="whoa"><span class="blah">garbage</span>interesting stuff</div>
I want to extract only
I tried with
[:#whoa html/text-node] but I get
[:#whoa (html/left :.blah)] should do
is it possible to use the
-> macro with forms that don't expect the chained result as first parameter?
(-> [1 2 3] (as-> coll (map inc coll))) (2 3 4)
inverting relations is a set operation, right?
see also project, rename-keys etc.
a map is a function where the domain are keys are the codomain are values (both sets). map-invert inverts that function, swapping the domain and the codomain?
I have a question about Clojure immutability and
def. Am I right in assuming that Clojure is immutable in the sense that I cannot modify data inside an existing Clojure collection (as opposed to a Java collection which can be mutated), but this has nothing to do with defining data using
def can be used to redefine a data collection which has nothing to do with Clojure being immutable?
Here is an example of what I'm referring to with mutating an existing collection:
(def initial-data (long-array (range 5))) (seq initial-data) ;; (0 1 2 3 4) (def test-j (seq initial-data)) (def test-c (seq (into-array Long/TYPE initial-data))) (seq test-j) ;; (0 1 2 3 4) (seq test-c) ;; (0 1 2 3 4) (aset initial-data 0 99) (seq initial-data) ;; (99 1 2 3 4) (seq test-j) ;; (99 1 2 3 4) (seq test-c) ;; (0 1 2 3 4)
@yogidevbear you are right
def creates a var, a var is a mutable container
Perfect, thanks for the clearer definition 🙂
I thought that was the case so glad I'm not getting it completely wrong
we have many ways of holding immutable data in a mutable container - var, atom, ref, agent
@yogidevbear Clojure takes the pragmatic approach of letting you use mutability in places where it is convenient, and provides you the tools to deal with it. I don’t think you would ever want to mutate a var at runtime (@noisesmith?), but Clojure has “atoms”, “refs” and “agents” which all provide some way to mutate data at runtime in a controlled manner
That all makes sense 👍
@hmaurer well, the repl is a kind of runtime of sorts, but yes, you want to hold something in another container if you intend to mutate it programmatically
@noisesmith oh right, but the repl is a special-case in my mind
Anyone know how to convert a time instance into a datetime?
i feel like this should be something like
FML i didn't see the coerce lib, there goes an hour of my life.
also, a more fudenemtal question "how does the
#inst "..." syntax even work?
@drewverlee here's some info: https://clojure.org/guides/weird_characters#tagged_literals
Here are the default-data-readers defined in core.clj: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L7681
And here's the DispatchReader defined for "#" in LispReader.java https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L106
TaggedLiteral-s are then read in LispReader's
readTagged method: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L1418
Hi again 🙂 I was wondering about shorthand function syntax
#(). Is it possible to pass in multiple arguments to the shorthand function and then refer to them using something like the
% syntax from within the shorthand function. Like
(filter #(true? (:some-key %)) some-collection), but for multiple arguments (not just one argument of
I think for the short hand anymous function you can only use the index of the argument 1 2 3 4... so %1 %2 %3...
Thanks @drewverlee. I tried that, but it didn't work the first time which is why I was asking here. I must have had a silly typo somewhere
@yogidevbear can you post what you have?
(reduce #(+ %1 (:keyword %2)) 0 coll)
☝️ this is working