This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-31
Channels
- # aleph (3)
- # aws (5)
- # beginners (65)
- # boot (17)
- # cljs-dev (112)
- # cljsrn (5)
- # clojure (146)
- # clojure-austin (3)
- # clojure-dusseldorf (3)
- # clojure-italy (18)
- # clojure-norway (13)
- # clojure-russia (84)
- # clojure-serbia (5)
- # clojure-spec (24)
- # clojure-uk (84)
- # clojurescript (204)
- # css (1)
- # cursive (21)
- # data-science (3)
- # datascript (21)
- # datomic (26)
- # emacs (5)
- # euroclojure (1)
- # hoplon (8)
- # jobs (7)
- # jobs-discuss (2)
- # keechma (35)
- # lumo (92)
- # mount (1)
- # nrepl (2)
- # numerical-computing (16)
- # off-topic (10)
- # om (58)
- # re-frame (13)
- # reagent (90)
- # remote-jobs (2)
- # ring-swagger (1)
- # spacemacs (9)
- # specter (6)
- # unrepl (17)
- # untangled (56)
- # yada (2)
Hi everybody, I'm announcing a Clojure client for letsencrypt. https://github.com/danielsz/certificaat/
@danielsz Nice. š Maybe also announce in #announcements?
Hey everybody, I have a quote about Clojure and FP in my head that goes something to the tune of, āWith functional programming, you define the problem, you define data structures that solve that problem, and then you write functions to operate on those data structuresā or something like that. I think it was in a Clojure talk. Anybody know where this is from?
@stephenmhopper was it the talk about modeling domain first? with a computer game as an example?
anyone have an idea how I could refactor this code?
(defn average-numeric [series]
(let [limited (take average-days series)
length (count limited)]
(->> limited
(map :value)
(reduce +)
(* (/ length)))))
It used to be all lets for each of the steps in between, both the */ (because thread-last) and re-using limited feel weird
I prefer lets when you are doing multiple transformations. Makes the meaning of your intermediate values explicit if you give them good names.
@clj.max Yep, I think it was this one: https://www.youtube.com/watch?v=Tb823aqgX_0
I remember that talk, pretty cool. Especially because I've played that game before š
Im wondering what might be a decent way to execute code based on matching namespaced keywords. For example, in some cases I want to execute based on a namespace match, sometimes based on namespace+name, and other times just on name.
Is there a way to stop pprint from putting commas in the output?
e.g. {:a 1, :b: 2}
Has anyone tried running lein repl in azure kudu console. I managed to launch the repl but then it kind of stuck and not responding to my input. After sometime the console gets reset.
@iku000888 there's a (half) broken way to do it looking up (:impls IFoo)
Is there any clojure.core macro or workaround usage pattern, for referring to one map key while initializing another, all in a single map-initialization form?
@iku000888 satisfies? would be the clean way to get around this, but I don't know your use case
@rauh thanks, but I think I'd rather write a macro, perhaps one wrapping around such an as->
impelmentation
how does as->
effectively defer from a let
statement? looks like the only difference is it returns only its last computation. Am I mostly right in that?
It's just implemented as a long let
. But plumbing is exactly what you want and much faster.
well going back to my original use case, I already have a let
where one value is built from the other, the problem is I wish to write them all into a map in the end. that map looks very silly, it has the form {:a a :b b :c c ....}
Did you check the link I posted? It's exactly what you're asking for. Building maps with dependencies in between
out of curiosity, why are clojure let bindings syntactically vectors and not maps? Is it just "lisp convention" or is there a practical reason?
@rauh do you use plumbing very often? https://github.com/plumatic/plumbing#graph-the-functional-swiss-army-knife
well, seems heavily starred on github š yet kind of a DSL on top core clojure. thanks again š
Does anyone here happen to know how to change the locale when using format? https://stackoverflow.com/questions/44281495
@misha reloaded workflow
@robert-stuttaford yeah. reading into that right now, thanks. Though, "workflow" never sounds easy
@misha the tools.namespace library has a refresh
REPL function that clears out namespaces before reloading.
@misha You can use ns-unmap: https://clojuredocs.org/clojure.core/defmulti
@misha, another trick is to def
the same symbol just before defining the defmulti, for reloading
(def foo nil)
(defmulti foo :type)
(defmethod foo ..)
@pesterhazy @jfigueroa nice, both require to re-eval defmethod
s after, so those are ok, if all defmethod are in the same place, thanks
right, that's (part of) the reason why multimethods don't have the same reloading semantics as defns
is there any codecamp kind of stuff which help me start with Clojure
@paragmedsinge http://www.braveclojure.com/ might be a good resource. Not a codecamp but has examples for you to code along with.
is there a way to force transit to cache a certain value (certain = 5th in this vector)?
this is snippet of datascript db's transit string as of now:
[94,"^A",28,536870913]],["^N",[94,"^C",3,536870913]],["^N",[94,"^2",100,536870913]],["^N",[94,"^K",4,536870913]],["^N",[94,"^<",3,536870913]],["^N",[94,"^E",10.5,536870913]],["^N",[95,"^A",18,536870913]],["^N",[95,"^C",3,536870913]],["^N",[95,"^2",100,536870913]],["^N",[95,"^K",77,536870913]],["^N",[95,"^<",3,536870913]],["^N",[95,"^E",1,536870913]],["^N",[96,"^A",24,536870913]],["^N",[96,"^C",3,536870913]],["^N",[96,"^2",100,536870913]],["^N",[96,"^K",6,536870913]],["^N",[96,"^<",7,536870913]],["^N",[96,"^E",116,536870913]],["^N",[97,"^A",16,536870913]],["^N",[97,"^2",1,536870913]],["^N",[97,"^K",78,536870913]],["^N",[97,"^<",3,536870913]]
it seems I can do (str tx) on transit-write, and (int tx-str) on-transit-read. need to run some perf and length benchmarks
Hi Guys, I have memory issues, I'm running out of memory doing (take 1000 (iterate update-state initial-state)), this is because state is pretty large. If i were to thin the iterates, by doing say, (take 100 (take-nth 10 (iterate update-state initial-state))) do I use 1/10 of the memory space? Or does it still store the whole 1000 iterations in memory and return every 10'th one
@michaellindon How does update-state work?
it just maps a map to another map
initial-state is a map
Based on what? Does it take in user input or something?
no it just contains some different data structures, no user input
If update-state returns the predictable input based on the iterator and the state, then you probably don't need to take any except the last piece of state
so for my application, im doing markov chain monte carlo, i need all the iterated values, if thats not possible i can thin the chain, and take every n'th one
@dpsutton i thought iterate was a lazy sequence, to some extent
iterate is lazy, but if you need to calculate n-1
to get n
, then it all n
still get calculated
@captainlexington i do indeed need to n-1 to get n... however cant some of these be garbage collected if n modulo 10 is not zero?
Oh I see - you don't want to skip the calculations, you just don't want to store all that data after they've been calculated?
exaxctly š
i need the 9th state to get the 10th state, but after that i dont need 9 any more
Then I think your original snippet would do what you want
ok, thanks for clarifying, i take it then that only the iterates divisible by 10 get stored in memory, and the other iterates get garbace collected after they've been used.
@ghadi i need more than just the last one š
its motivated by the application
im generating autocorrelated samples from a probability distribution
but because they are correlated, i can take every n'th one, and not lose a lot of information
i think my question has been answered. Thank you. I understand the (take 100 (take-nth 10 approach to use 1/10th of the heap than (take 1000
im going to check this empirically, it doesnt seem to be the case when i am checking the heap usage by visualVM
can you increase the memory of your jvm and see if that alleviates the problem? not that this is the best solution but this could confirm that its just the size of the maps
maybe after the whole thing is executed, the other iterates get garbage collected, but while the iterations are running i think they are all still in memory
i can try increasing the heap size too
because the line hasn't finished executing, im not sure if the other states aren't getting garbage collected. I think they may get garbage collected once (take 100 (take-nth 10.... completes
i was hoping that the 9th iterate would get garbage collected as soon as the 10th iterate was computed. but it looks like its building up all the iterates in memory and then when it completes it will garbage collected the unwanted iterates
ill let you know if theres a dramatic decrease in heap usage when the iteration has fininshed
@michaellindon btw there is a sample transducer for making fair samples of a lazy-seq
=> (doc random-sample)
-------------------------
clojure.core/random-sample
([prob] [prob coll])
Returns items from coll with random probability of prob (0.0 -
1.0). Returns a transducer when no collection is provided.
nil
@michaellindon You may also be better served by a reduce, since you don't' need the results of every iteration.
iterate was a chunked seq until 1.7 if I recall, which has memory usage implications
you might want to check your state stepping function to ensure you are taking advantage of structural sharing
@noisesmith I think this is along the right track, can you perhaps elaborate a little please?
itās a function / transducer meant for collecting a sample, like a randomized take-nth
I'll look into it, thanks
Saw this posted on the Clojurians Discord and figured Iād re-post here ā as a good talk about introducing new technology (e.g., Clojure) into a company: https://www.youtube.com/watch?v=GCsxYAxw3JQ
@olikasg Fundamentally map is lazy. You only see the error because the repl tries to print the list, which is not lazy.
i believe it is laziness. the debugger forces realization of the whole list inside the scope of the try catch. In non-interactive mode, you are not actually computing those values until you are consuming them, far away from the try catch.
The try block you have written exits immediately, then the repl tries to realize the list in order to print it, and it blows up, because it's calling #(Integer/parseInt %)
and that is not in a try/catch
the easy fix to this in general is to put the try directly on the thing that errors, inside the lazy-seq
So if I understand correctly (try (anything-lazy) (catch ...))
does not catches any exceptionsā¦
exceptions happen when you execute code, laziness defers code execution, a try catch has to be around the execution to catch an exception
Thanks for the help. I used (vec (map ...))
to realise to list. I need a vector anyway. But @hiredmanās solution seems more generic for the future. And it raises another question: is the bindings vector lazy in let
?
a function is also a suspended execution, and similarly, you can use it as a value without getting an exception until you invoke it
clojure is a strict language (the evaluation semantics are not lazy) but, as in most strict languages, you can construct values that represent computations
a function is one sort of value that represents a computation, a lazy sequence is another
sure, I know I can be someone pedantic about these things, but I don't know your background or experience level with this sort of thing, so I am trying to make it as clear as possible and relate it to other concepts typically encountered
clarifications are always welcomeā¦ I am not new to functional programming, but there are no laziness in Erlang š
@olikasg just for the record using mapv
or transducers when you know what the shape of your output should be and you know you don't want lazy computation will be both more efficient and read a little better
Anyway, a small clarification to your example:
(let [f (fn [] (throw (Exception.)))] (try (f) (catch Exception _)))
forcing a lazy value is equivalent to function invocation. so moving the function invoke inside the try/catch is like calling dorun on a lazy sequence inside a try/catch
http://chrisbriones.com/posts/getting-lazy-with-erlang seems like a blog post creating something like lazy seqs in erlang