This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-22
Channels
- # adventofcode (1)
- # beginners (172)
- # boot (47)
- # cider (7)
- # cljs-dev (30)
- # cljsrn (43)
- # clojure (180)
- # clojure-dusseldorf (1)
- # clojure-greece (1)
- # clojure-italy (3)
- # clojure-russia (41)
- # clojure-spec (67)
- # clojure-uk (101)
- # clojurescript (128)
- # core-async (4)
- # cursive (13)
- # datomic (29)
- # devcards (5)
- # emacs (19)
- # events (1)
- # hoplon (38)
- # lein-figwheel (1)
- # luminus (8)
- # midje (1)
- # off-topic (47)
- # om (10)
- # onyx (23)
- # protorepl (1)
- # re-frame (11)
- # reagent (7)
- # ring (3)
- # ring-swagger (9)
- # rum (6)
- # sql (5)
- # untangled (4)
When you write code that manipulates deeply nested datastructures and then look at it an hour later and wonder how it came to this. But then all the tests pass so... Ship it!
I vaguely remember seeing Nathan's talk a while back. Lets see if specter can make this code pretty
is there a function where I can wrap a function in the regex replacement? basically (clojure.string/replace s #āsome-regex" ā$1ā f)
and the substitution for each match would be f(match).
the normal version of clojure.string/replace
that takes a function doesn't suffice?
e.g., (clojure.string/replace "thomas" #"[aeiou]" #(str % %)) => "thoomaas"
how to get java class function's console out put when working in clojure?My java class has System.out.println
but I have not seen them in clojure repl. like (.method-that-uses-println (new MyClass))
,what happened?
@sound2gd how are you starting the jvm?
in a terminal? and you're calling that code from that same terminal?
does the output happen in the terminal window where you called lein repl
?
but you did call lein repl
yourself, you didn't have cider start it for you?
if you started it yourself and don't see the output in the terminal, then I don't know.
System.out.println
doesn't generally go to the same place as (println)
, especially using editor integration
I would try a standalone lein repl
without any cider or emacs
what?
I wasn't suggesting you permanently give up emacs & cider, I mean just to debug your current problem
cider cause it ,I call (.println java.lang.System/out "12345")
and don't see the output,but in terminal I get it ,thanks @gfredericks
Does anyone here use Spectre? Can you give a brief experience report? Yay or Nay? If its anywhere as good as Haskells lens lib, Iām sold š
@alexisvincent I can not compare it to any other lens lib, but for me it is a definit yay as soon as my maps gain a depth > 2
my homepage looks like this. The first page can be found with just / . Next pages are found with /pages=x . Must I make two seperate routes or can one route handle both cases
@sveri and performance? It seems significantly slower when uncompiled
I wonder actually if the author wouldnt be able to cache compiled paths from inline usagesā¦ Shouldnt be hard?
@alexisvincent I only do personal stuff for me and never had to take care of that, so I can not answer your question. That said, in general, wait and see if you hit performance problems within your application at all and if so, if they are specter related.
@sveri cool cool
@sveri @alexisvincent inline caching was implemented in Specter awhile ago, and it's blazing fast
no need for manual compilation anymore
in many cases it's actually difficult to write code that's faster than specter
yes, update-in
in 1.8 and below is quite slow actually
@alexisvincent Specter is a generalized approach to transforming and updating immutable data structures, encompassing things like get-in, update-in, assoc-in, map, filter, and a lot more. To get my feet wet, I decided to use it for a day in place of all the spots where I'd typically use get-in, update-in, or assoc-in (in many cases, Specter is faster than the Clojure built-ins, so there's no reason not to do that). Before I knew it, I was seeing all sorts of other places in my code that could be made more elegant with Specter. I'm not 100% convinced that Specter has been distilled down to the simplest possible set of composable navigators - the fringes of the library still seem pretty complicated to me. But even if you stick with the core, bread-and-butter navigators of Specter and ignore the parts you don't understand, it's definitely a win over vanilla Clojure. Only real downside I can think of is that because it puts the navigator as the first input rather than the data structure, and doesn't take extra optional inputs for the transform, it's not as swap! friendly as update-in.
update-in
is improved for 1.9 but specter is still 30% faster
@sveri To better understand intuitively why Specter is faster than update-in, basically update-in with something like [:a :b: :c]
as the keypath is dynamically traversing that sequence every time it is called, whereas Specter analyzes it once and figures out that it can just rewrite the code as (:c (:b (:a m)))
.
@nathanmarz @puzzler Ah, my first guess was that you are doing some native Java stuff underneath, but instead, you transform it to a different AST, right?
we use enlive pretty heavily. i wonder how much of a boost a specter based system would give us
since enlive is really just a dsl for manipulating a nested map structure with a small set of known keys
If you call it with a general keypath that's in a variable like path
, Specter can't do as much with that so it falls back to a strategy like update-in. At least, that's my understanding. Nathan's the expert, of course.
not exactly, actually it's super fast in pretty much all cases
these pages go into the implementation: https://github.com/nathanmarz/specter/wiki/Specter-0.11.0:-Performance-without-the-tradeoffs https://github.com/nathanmarz/specter/wiki/Specter's-inline-caching-implementation
@nathanmarz In theory, if you only are using a given callsite once, are you paying a slight perf penalty?
unfortunately I don't have a single up-to-date resource on how the implementation works
@puzzler yea, but it's extremely minor
two getfield's basically
nice to see transducers in the perf comparisons
oh you mean with the compilation
yes, the first time through will be slower
@nathanmarz thanks š nice lib š I watched your video earlier and thought you were still doing explicit path compilation
@puzzler Thanks for the experience report
Hello everyone! Does anyone use this library? https://github.com/Otann/morse
I'm new in Clojure and I have some problems trying to create my bot.
It silently stops right after the lein run
. I've copied the code from the readme but nothing works.
@riseremi It might be that it starts in another thread. So you need to block your main thread so that it doesnāt exit
@alexisvincent I'll try that, thank you!
@nathanmarz Impressive, all in all, not only the lib, but also the posts about the technical details š
@alexisvincent it works. Thanks a lot :thumbsup:
@riseremi This bit me when I started with clojure as well š
@sveri @alexisvincent feel free to drop by #specter if you have any questions
@nathanmarz i remember you said you were working on spectre with graphs but it wasn't ready for primetime. Has that been implemented yet?
@dpsutton I have an extensive set of navigators built on top of Loom that I have not open-sourced
I want someone from the community to make an open source version (with my guidance)
so far there haven't been any takers
yea, specter is completely extensible
defnav
no, i made storm
i am trying to find the respective documentation for this https://nodejs.org/api/modules.html#modules_all_together in clojure. My issue is that I am not even aware of the accurate keywords too google in this case, could someone give me some pointers please?
maybe this: http://clojure.github.io/clojure/
this is more like about the build processes, what are my options on where I can "require" from, I realize that in clojure there is no unique "require" and build process but as I said, i am not even sure what to look for
so when you are writing something there has to be a number of options on how to require dependencies, the link i shared contains the accurate description how the string is interpreted that is given to require. I am trying to find the same solutions in clojure land, at the same level of detail
Maybe this? http://stackoverflow.com/questions/7143406/what-are-the-differences-among-require-import-and-use
that certainly helps, thank you, however my problem with these stackoverflow answers that i can not be sure they are exhaustive
You might want to follow the link: http://clojuredocs.org/clojure.core/require
I am not sure if you are asking because you want to write documentation or something similar or just need some practical advice for day to day work.
not sure why everyone is suggesting beginners to write clojure documentations, no wonder it looks how it looks
Tbh. I have not found any documentation on the point for your question. At least none that says: these are all the options you have.
Here is something that comes close I guess: http://clojure.org/api/cheatsheet
well, the environment is more complicated than in node, it would be unfair to ask for the same thing, i am just collecting all the relevant docs and hopefully it will be somewhat complete š
My personal and subjective opionion is that node is the developers hell where writing assembler is the land of the sanes compared to it. And I find the clojure sphere way easier to understand and get into.
@ashnur the documentation on clojure.core/require
and clojure.core/import
are going to be the two best places to find what you're looking for
The clojuredocs site copies that verbatim ^^
I find https://stuartsierra.com/2016/clojure-how-to-ns.html to be a pretty useful overview of the parts of ns
that you should probably use 99% of the time
my homepage looks like this. The first page can be found with just / . Next pages are found with /pages=x . Must I make two seperate routes or can one route handle both cases
@roelof I would suggest you take a look at: https://github.com/weavejester/compojure/wiki/Routes-In-Detail this should answer your question š
im trying to save an array of images to my postgres db. This is the ring handler:
(POST "/file" []
:multipart-params [files :- [TempFileUpload]]
:current-user user
(doseq [file files]
(db/save-image! user file))
(ok))
If the images are small (< 50kb) all the images gets stored to postgres no problem, but if the images are bigger the operation takes too long and i get batchupdate exception.
How can I ensure that the image is stored before the next image is processed?@roelof Usually pagination is applied as parameter, so it would be "/?page=3&per_page=10" or something similar.
From my point of view thats one route then which takes extra parameters, where the parameters can be empty of course and take a default value then.
@roelofw actually you can do it with one route.
if it's a query param
@roelof Actually we mean the same. The query parameter can be ommitted, and if it is, you want to deliver the first page and x images
@roelof You need to read more about the topic in general. Read up on designing APIs with parameters.
@roelofw try stepping back for 30 mins and reading about compojure routes. Then think about what if the parameter was nil what could you do to provide a default (presumably page 1)
It's better to try and understand the topic of routing in general than look for a specific answer that way you can figure out what to do in a different scenario.
@sound2gd @gfredericks - cider puts java output in a hidden server buffer, this is considered "won't fix, working as designed" by the cider team. The fixes are using cider connect to a repl running in a regular terminal, or checking the automatic hidden buffer that cider puts your output in
I always forget what the name of that hidden buffer is though
@noisesmith I thought of that but @sound2gd kept saying that they started lein repl
manually
but then mentioned cider-jack-in - I assumed it was a miscommunication of some sort
oh, I just misread, sorry for the noise
good night everyone. Iām trying to do a hashmap with all prefixes from an argument my solution was:
(defn prefixer [word]
(first (reduce (fn [[out prefix] current]
(let [entry (str prefix current)
updated (update-in out [entry] #(if %1 (inc %1) 1))]
[updated entry]))
[{} ""]
word)))
that will outputs
(prefixer "olivia")
=> {"o" 1, "ol" 1, "oli" 1, "oliv" 1, "olivi" 1, "olivia" 1}
@oliv are you familiar with the reductions
function?
never used @manutter51
I donāt know if thatās helpful or not, but thatās what the shape of your output reminded me of
Hi, I'm looking for advice on how to get output of eg. tcpdump into a core.async channel. clojure.java.shell doesn't look like the right tool. Anyone?
"tcpdump" could be replaced by "tail -fā or anything else that gives an āendlessā stream of output.
it's also quite straightforward to use ProcessBuilder to make a Process yourself - sometimes treating input as a stream is actually easier than treating a lazy-seq that comes from a stream as a stream
especially since your destination is a channel
@nikki that wouldnāt work without direct support in the compiler since both a
and b
would need to be evaluated.
but if there was some other conditional special form and if
wasn't you could impl as a macro to do no-eval of a
or b
too still
you could write a macro to do something like rewrite the code with thunks everywhere like so