Fork me on GitHub
#beginners
<
2017-10-17
>
athomasoriginal01:10:38

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)

noisesmith01:10:26

you can also use (swap! app-state update :keys-pressed conj some-value)

noisesmith01:10:00

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

noisesmith01:10:55

(swap! app-state conj :keys-presed some-value) ends up calling (conj @app-state :keys-pressed some-value) which isn't valid

athomasoriginal01:10:06

well that explains the error

1128613:10:19

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

1128613:10:53

however, when it clojure calls the init method, it throws a notfound exception for clojure/core.clj

1128613:10:31

the jar is a uberjar created with lein

noisesmith15:10:33

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

1128606:10:36

@noisesmith I'm using the one with all the deps included (standalone)

1128607:10:32

That is why I don't understand it cannot find the clojure/core.clj. It is in the jar 😕.

noisesmith16:10:35

what is the exact message - with stack trace if possible?

noisesmith16:10:56

oh, and the command line you ran too

1128607:10:37

I will collect the stack trace tonight

1128607:10:02

The jar is loaded from another program, that allows java extensions provided as a jar

noisesmith18:10:14

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

noisesmith18:10:11

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

1128608:10:21

makes sense, thanks for the info. Will look into it 🙂

1128608:10:06

I expected that the genclass would have taken care of this though

1128608:10:42

perhaps clojure is not on the cp

1128608:10:58

will investigate this further, thanks for the help!

1128613:10:15

there is also another class that defines a main function and that runs fine when called with java -jar X

vmajsuk20:10:16

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?

noisesmith20:10:52

@vmajsuk I don’t think 4clojure uses a new enough version for transducers

noisesmith20:10:36

and for equality, clojure thinks [1 2 3] and (map identity [1 2 3]) are equal even if the types differ

noisesmith21:10:14

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)

noisesmith21:10:45

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))

noisesmith21:10:12

or (into {} (for [[k v] m] [(f k) (g v)]))

vmajsuk21:10:44

Got that, thanks a lot!

noisesmith21:10:44

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

noisesmith21:10:15

(eg. implementing group-by)

vmajsuk21:10:31

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?

noisesmith21:10:50

group-by is built in - most of the best collection ops are built in

noisesmith21:10:07

but iirc one 4clojure problem has you implement group-by - I just meant that general sort of problem

noisesmith21:10:45

there are definitely popular collection libraries for extra features / performance / data types though

vmajsuk21:10:26

Ok, I'll investigate this later. Thanks for the help 🙂

raymondm21:10:14

Hey friends! I am working on HackerRanks functional programming questions. Specifically trying to work on this:

raymondm21:10:19

Notice that this can be simplified infinite series specified by:

raymondm21:10:36

I would only be interest in the first 10 terms of the series, say 10.

raymondm21:10:17

I know having generated an infinite series, I can take 10 to get these. I am struggling with defining the infinite series.

raymondm21:10:36

Sorry for all the notifications, still getting used to slack.

noisesmith21:10:49

with clojure we use lazy-seq for low level implementation of such things, but there are easier things like range and iterate as well

noisesmith21:10:38

as well as things like map and filter etc. that return a lazy indefinite thing if the input is lazy and indefinite

raymondm22:10:16

@noisesmith That’s really helpful. Thank you!