This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-16
Channels
- # aleph (2)
- # beginners (68)
- # boot (25)
- # bristol-clojurians (5)
- # cider (10)
- # cljs-dev (60)
- # cljsrn (1)
- # clojure (138)
- # clojure-austin (1)
- # clojure-france (2)
- # clojure-greece (11)
- # clojure-italy (4)
- # clojure-russia (16)
- # clojure-spec (4)
- # clojure-uk (75)
- # clojurescript (26)
- # core-async (28)
- # cursive (25)
- # data-science (4)
- # datomic (16)
- # defnpodcast (2)
- # devops (2)
- # docs (10)
- # duct (11)
- # emacs (1)
- # events (1)
- # figwheel (8)
- # fulcro (61)
- # garden (2)
- # hoplon (6)
- # java (6)
- # jobs-discuss (1)
- # lein-figwheel (14)
- # leiningen (86)
- # luminus (11)
- # off-topic (8)
- # parinfer (9)
- # pedestal (2)
- # re-frame (19)
- # reagent (1)
- # ring (3)
- # ring-swagger (8)
- # shadow-cljs (278)
- # spacemacs (13)
- # sql (5)
- # testing (7)
- # unrepl (8)
- # yada (25)
does anyone know why (
would work in CIDER, but fail in an uberjar/running lein repl
with a 403 error from the server?
Could somebody explain what the ^
is doing here
(def giants
(with-meta 'Giants
{:league "National League"}))
(meditations
"Or more succinctly with a reader macro"
(= __ (meta '^{:division "West"} Giants))
It’s setting that hash-map as metadata on Giants
haha, haven't written any macros yet but I can see that if you can just grab any piece of code, traverse it and modify it then yeah, god-mode definitely applies!
Would it be outrageous to use macros to add side effects? i.e. keep your program pure and then mix in the side effects afterwards
Are there any clojure implementations of katas that have been written in an idiomatic style? Would be great to read some simple code that's written idiomatically.
ha, yeah, don't worry I'll use them sparingly 🙂 I'm curious how side effects are handled in clojure though, are there some idioms for how to separate them from your pure code?
@oliver089 in the core are some nice examples, most functions like merge, are either macro’s or functions calling other functions
(defn merge
"Returns a map that consists of the rest of the maps conj-ed onto
the first. If a key occurs in more than one map, the mapping from
the latter (left-to-right) will be the mapping in the result."
[& maps]
(when (some identity maps)
(reduce #(conj (or %1 {}) %2) maps)))
I take it that once code has been evaluated it's harder to grab the code? i.e. I can't do
`merge
and get the original sourceFor characters in Clojure that are difficult to Google, one reference is this page: https://clojure.org/guides/weird_characters
Once you mostly know what they are, there is a section of the Clojure Cheatsheet in the bottom left that has them in a more compact form: https://clojure.org/api/cheatsheet or I like this form of it a bit better: http://jafingerhut.github.io/cheatsheet/clojuredocs/cheatsheet-tiptip-no-cdocs-summary.html
@U0CMVHBL2 thanks, that's very useful!
hi, I just read in the cljs-ajax repo this sentence: "More generally, it's time to move away from EDN on the browser..." why? I wanted to use edn for my webapp but now I don't know. basically I struggle with keywords, that need constant parsing, because in json-format they are always stringified...
the better thing to use for sending data to the browser is Transit, which supports all the types and extensibility EDN does, but encodes to and from JSON: http://blog.cognitect.com/blog/2014/7/22/transit
Hi guys
if i have list of records like this: [{:x 10 :y 0} {:x 4 :y 7} {:x 0 :y 10}], what i would like to achieve is: get all records which not satisfy x != y, i have done it linear by 2 loops but this isn't efficient if i have much records, is there any suggestion in this
Sound like you need to use filter
for that
(filter (fn [{:keys [x y]}] (not= x y)) [{:x 10 :y 0} {:x 4 :y 7} {:x 0 :y 10}])
i want comparing x and y from the same and other records
[{:x 10 :y 0} {:x 4 :y 7} {:x 0 :y 10}] for this example: {:x 4 :y 7} should be the result
because first and last are satisfy condition
but imagine we have 50k records for example
so the worst solution is: have 2 filters which iterate for each record and compare with the whole list
but that's very slow
(let [data (repeatedly 50000 (fn [] {:x (rand-int 40000) :y (rand-int 40000)}))
xs (set (map :x data))
ys (set (map :y data))]
(filter (fn [{:keys [x y]}]
(and (not (contains? xs y))
(not (contains? ys x))))
data))
@rcustodio yeah I have used langohr for rabbitmq integration
@pcbalodi did you faced this problem https://github.com/michaelklishin/langohr/issues/24#issuecomment-22644418
No, I had a requirement of using mutiple channels actually, so I didnt know about this issue at all 😄
What do you mean? Each consumer with its channel or 1 consumer have several channels?
is there a loop in clojure similiar to [1,2,3].map(x => x)
in js in terms of simplicity
thanks
there’s libraries - cheshire and clojure.data.json are both popular
it would look something like that @josmith2016 via https://github.com/dakrone/cheshire
I just did (ns my.ns (require [c.c.matrix] [c.c.matrix.linear]))
and it works fine. But when I also require [c.c.matrix.select]
I get java.io.FileNotFoundException: Could not locate clojure/core/matrix/select__init.class or clojure/core/matrix/select.clj on classpath
. I am using leiningen and vectorz-clj. Does anyone know how I might fix this?
@xhve4lf3w7 Looks like it should be [clojure.core.matrix.selection]
, not select
.
Based on the files/namespaces here https://github.com/mikera/core.matrix/tree/develop/src/main/clojure/clojure/core/matrix
@seancorfield Indeed. I went by the API docs (https://mikera.github.io/core.matrix/doc/index.html) but didnt pay attention to the version (0.44.0). Well thank you!
If I have a multi arity function like this
(defn messenger
([] (do-something 1) (do-something 2))
([blah] (do-something 1) (do-something 3)))
You will notice I am calling the same function with the same argument in case 1 and 2 (do-something 1)
. Is there a way to just call that function no matter what without manually specifying it in each arity list?You could consolidate the multiple arities into one function with one optional parameter, then call (do-something 1)
, check if blah
is nil?
, call (do-something 2)
if it is, else call (do-something 3)
I saw that was an option, but I read through this https://stuartsierra.com/2015/06/01/clojure-donts-optional-arguments-with-varargs and it seems to go against the above.
It’s a common convention in Clojure to have something like
(defn foo-fn
([] (foo-fn nil))
([bar] (do-something 1) (do-something 2)))
where the lower-arity function calls the higher-arity function with some reasonable defaultsSo that avoids the problem you’re asking about
But in the specific case you mention, I think that’s kind of a code smell — if it’s doing different things, it arguably should be different functions
arity matching is just about the only kind of pattern matching we have natively
Hello all, I'm new here. I decided instead of always bugging my only friend who knows clojure, I'd try asking community members. I need to create a function that accepts multiple optional arguments. For a caller to be able to just pass values for some parameters but not others, would it be best to use a hash-map parameter and take the values from it? If so, is there a way in the function declaration to destructure the values from the hash-map into named keys, especially so that a caller could see the optional parameter names in intellisense. Here's is the signature I started to write for two optional parameters, but realized this was a code smell because they are ordered, optional params.
(defn get-orders
[& [statuses product-id]]
( ))
The "Associative Destructuring" section of this Clojure guide shows how to do destructuring of maps. This can be done in function argument definitions, as well as let/loop/etc.: https://clojure.org/guides/destructuring
@brandon.ringe there are two main ways of doing this, either by passing an actual hash-map to the function, or by using 'named' arguments syntax:
user=> (defn foo [{:keys [a b]}] (+ a b))
#'user/foo
user=> (foo {:a 2 :b 3})
5
user=> (defn bar [& {:keys [a b]}] (+ a b))
#'user/bar
user=> (bar :a 2 :b 3)
5
named arguments are somewhat unpopular because they are harder to compose