This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-17
Channels
- # beginners (45)
- # boot (33)
- # chestnut (9)
- # cider (2)
- # cljs-dev (24)
- # cljsrn (1)
- # clojure (114)
- # clojure-conj (3)
- # clojure-dev (3)
- # clojure-dusseldorf (3)
- # clojure-greece (5)
- # clojure-italy (22)
- # clojure-russia (10)
- # clojure-spec (12)
- # clojure-uk (19)
- # clojurescript (117)
- # core-async (16)
- # cursive (3)
- # data-science (1)
- # datomic (5)
- # docs (13)
- # emacs (1)
- # fulcro (13)
- # graphql (1)
- # hoplon (20)
- # immutant (3)
- # jobs (1)
- # juxt (12)
- # lein-figwheel (1)
- # luminus (4)
- # off-topic (12)
- # onyx (61)
- # portkey (1)
- # re-frame (21)
- # reagent (26)
- # ring-swagger (38)
- # rum (1)
- # shadow-cljs (222)
- # slack-help (4)
- # spacemacs (11)
- # specter (67)
- # uncomplicate (236)
the description in the docs for update-in
is throwing me off. Why do I need to use update-in
in this case. I was under the impression that update-in
is meant for accessing nested structures. Here is the code I am referring to:
(def app-state (atom {:keys-pressed []}))
;; does not work
(swap! app-state conj :keys-pressed some-value)
;; works
(swap! app-state update-in [:keys-pressed] conj some-value)
you can also use (swap! app-state update :keys-pressed conj some-value)
the one that won't work fails because conj doesn't work like that, and swap! isn't a syntax, it's a function that uses the function and args you pass it
(swap! app-state conj :keys-presed some-value)
ends up calling (conj @app-state :keys-pressed some-value)
which isn't valid
well that explains the error
Thanks!
hi, I'm trying to use clojure to create a Burp extension, basically a jar with a java class burp.BurpExtender that implements some interface
however, when it clojure calls the init method, it throws a notfound exception for clojure/core.clj
a common thing to double check is that lein uberjar
creates two jars, one is a regular jar and one is the actual uberjar, so a simple thing is to make sure you are using the right one
@noisesmith I'm using the one with all the deps included (standalone)
That is why I don't understand it cannot find the clojure/core.clj. It is in the jar 😕.
what is the exact message - with stack trace if possible?
oh, and the command line you ran too
OK -that makes this make much more sense. You need to ensure you use clojure via the proper API so that it is initialized. If you use the main for the uberjar this is done for you, but if you have classes that some other code outside clojure is loading up, you probably want a a small java shim that uses clojure.java.api.Clojure - here’s a simple example from a work in progress https://github.com/noisesmith/clj-jsvc-adapter/blob/master/src/java/org/noisesmith/Cljsvc.java
of course you don’t need the jsvc stuff ,but loading up require and requiring your ns and calling the right function - that should all be very similar to what you see in that example
there is also another class that defines a main function and that runs fine when called with java -jar X
Hi!
How can I apply handy functions like map
and filter
to a coll without changing its type?
I'm solving http://4clojure.com problems right now, and it seems awkward sometimes that filter
always returns a list.
Also, what is a right way to solve this kind of things (processing collections) in Clojure? Should I look into transducers?
@vmajsuk I don’t think 4clojure uses a new enough version for transducers
and for equality, clojure thinks [1 2 3] and (map identity [1 2 3]) are equal even if the types differ
which is all that should matter for most 4clojure problems (unless you need the behavior of a specific type, in which case making sure with vec / seq / set etc. is better anyway)
there is the case of iterating on a hash-map, the generalized version of the idiom you can use in 4clojure is (into {} (map (fn [[k v]] [(f k) (g v)]) m))
or (into {} (for [[k v] m] [(f k) (g v)]))
sometimes a better option is (reduce (fn [m [k v]] (assoc m (f k) (g v))) {} input)
but that’s only needed when previously attached data is needed in order to calculate this key or this value
(eg. implementing group-by)
I see. And is there a common library that is used for collection manipulations such as group-by or is it common to implement them yourself if needed?
group-by is built in - most of the best collection ops are built in
but iirc one 4clojure problem has you implement group-by - I just meant that general sort of problem
there are definitely popular collection libraries for extra features / performance / data types though
Hey friends! I am working on HackerRanks functional programming questions. Specifically trying to work on this:
I know having generated an infinite series, I can take 10
to get these. I am struggling with defining the infinite series.
with clojure we use lazy-seq
for low level implementation of such things, but there are easier things like range
and iterate
as well
as well as things like map and filter etc. that return a lazy indefinite thing if the input is lazy and indefinite
@noisesmith That’s really helpful. Thank you!