This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-13
Channels
- # beginners (67)
- # boot (18)
- # cider (28)
- # clara (11)
- # cljs-dev (1)
- # cljsrn (7)
- # clojure (134)
- # clojure-dev (2)
- # clojure-dusseldorf (1)
- # clojure-greece (1)
- # clojure-italy (13)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-russia (2)
- # clojure-spec (2)
- # clojure-uk (52)
- # clojurebridge-ams (1)
- # clojurescript (78)
- # core-async (1)
- # core-matrix (2)
- # cursive (12)
- # data-science (22)
- # emacs (10)
- # events (1)
- # fulcro (28)
- # graphql (4)
- # hoplon (16)
- # jobs (1)
- # lein-figwheel (3)
- # leiningen (3)
- # nyc (1)
- # off-topic (19)
- # onyx (70)
- # parinfer (2)
- # pedestal (1)
- # portkey (9)
- # protorepl (2)
- # re-frame (16)
- # reagent (39)
- # ring-swagger (5)
- # rum (1)
- # schema (2)
- # shadow-cljs (216)
- # specter (5)
- # sql (1)
- # uncomplicate (4)
- # unrepl (6)
- # vim (25)
- # yada (5)
How do I sort by the list of lists to make sure they are in sorted order ? I have '((1) (2) (3) (2 1) (1 2) (3 1) (1 3) (3 2) (2 3) (3 2 1) (2 3 1))
and I want it to be ((1) (2) (3) (1 2) (1 3) (2 1) (2 3) (3 1) (3 2) (2 3 1) (3 2 1))
. Is there an idiomatic way to do this ? sort
doesn't help. In sort-by
how can I compare two lists. (juxt first second)
doesn't help. It can have any number of elements for every sub-list. Expecting something like Python's sorted sorted([[1], [2, 1], [1, 2]]) # [[1], [1, 2], [2, 1]]
@tjtolton I don't see it listed here https://dev.clojure.org/display/community/Where+Did+Clojure.Contrib+Go so maybe it disappeared from Contrib before 1.3 appeared?
really nice for dev tooling/scripting against a ring server running in a docker environment. just set up all my things using some constants i defined up at the top, etc
What does duck-streams/slurp*
give you that the built-in slurp
does not?
(it says it's "like slurp but opens f with reader" -- but slurp
also seems to call reader
on f
...)
it actually seems to define its own reader, which is possibly obsolete now. I'm going to be honest, I just kind of wanted to make it work blackbox without inspecting the internals. And I'm getting what I deserve š
It's telling that duck-streams was deprecated even before the break-up of monolithic contrib that came with Clojure 1.3 š
Looks like you can just use the built-in slurp
(based on limited playing in the REPL).
boot.user=> ((juxt read slurp) (-> "Hello, World!" java.io.StringReader. java.io.PushbackReader.))
[Hello ", World!"]
(that's basically silent-read
without the try
/`catch`)@seancorfield could you elaborate silent-read
without the try
/`catch`?
@lovuikeng Based on the code in the blog that @tjtolton linked to. The blog uses old, outdated libraries but has a function that takes a string and tries to return a pair of the first readable (Clojure) form from the string and the rest of the (unread) string.
The full function (using built-in slurp
) would be
(defn silent-read
[s]
(try
((juxt read slurp) (-> s java.io.StringReader. java.io.PushbackReader.))
(catch Exception _)))
So it returns nil
if it can't read a form from the string.@tjtolton Did you get that interpolation example working?
And did you also see that the functionality is part of https://github.com/clojure/core.incubator/blob/master/src/main/clojure/clojure/core/strint.clj ?
So you can just depend on [org.clojure/core.incubator "0.1.4"]
and then require [clojure.core.strint :refer [<<]]
and use that?
thank you <@U04V70XH6>! `strint.clj`: _"originally proposed/published at <http://cemerick.com/2009%22_|http://cemerick.com/2009"_>, you just got to love Hickey :slightly_smiling_face:
sean@sean-xps:~$ boot -d org.clojure/core.incubator repl
nREPL server started on port 64540 on host 127.0.0.1 -
...
boot.user=> (require '[clojure.core.strint :refer [<<]])
nil
boot.user=> (<< "It is ~(java.util.Date.) right now!")
"It is Fri Oct 13 15:58:41 GMT 2017 right now!"
boot.user=>
(edited to remove the {
}
since they aren't needed)(I love that Boot lets me just pull in an arbitrary library without needing to create a project etc)
thanks for the great tips @seancorfield!
Now I must go grab lunch before the sessions start back up in 50 minutes!
sorted-map and sorted-map-by - thereās also one from a github project that preserves insertion order
you can also use the various java mutable hash-maps of course
@eraserhd I have a lot of respect for the author, but havenāt tried this code https://github.com/amalloy/ordered
@noisesmith Wow, thanks!
@bpiel Watching your talk about Guildsman right now. Super interesting but pleeease start thinking about writing readmes! š
@nooga ha! Thanks. I promise there'll be docs and examples once this is ready for the public. Missing README is not remotely the biggest problem
@bpiel some would argue that having a readme could attract more hands or heads to help you out š
@nooga Those hands/heads will be critical to success. But, I don't think anyone can help yet. Ex. there's no tests
@nooga that's very true. Actually, people can help, just not via the guildsman code yet
Does anyone know of a forum for asking Cider specific questions? Or perhaps this is the right place..?
does clojure have a builtin whee I provide: state f :: state -> state still-run :: state -> bool and it iteratively call 'f' on 'state' until (still-run state) becomes false ?
would (take-while still-run (iterate f state))
count?
only if you capture them
if you donāt bind them, they are gcd
I guess I'll just do a loop
`
(loop [state state]
(if (still-run state) (recur (f state)) state)))
(reduce (fn [prevoius-states current-state] (if (still-run current-state) (conj previous-states (f current-state)) (reduced previous-states)))
but thereās nothing to reduce over
that does a lot of extra work and a lot of extra syntax to do something like the take-while / iterate except itās not lazy and always holds all states in memory whether you need them or not, I donāt see any advantage
@qqq if range was the input current state would always be a number
(yes you could fix that by changing the binding vector to [previous-states _]
but that doesnāt really make things much better)
now, if f took a second arg, eg. one that delivers an event or message (a common design for me at least) (reduce f state (repeatedly get-event))
can be a decent way to do that (reductions instead of reduce if you need all the values in a sequence as they are produced)
this is a good setup if you have an external data source because it means you can unit test by passing in a lazy-seq of events that provoke the behavior you care about
Almost every tutorial explains basic routes using compojure and they donāt really go into details of middlewares and such
@bravilogy what sort of thing are you looking for?
Iām trying to build a SPA and I have an SQL database. And basically was wondering whatās the best approach to creating RESTful apis and working with databases?
#luminus is a good way to get started http://www.luminusweb.net
You can use the options for ClojureScript, Re-frame, Reagent, etc. for the SPA stuff, and I believe thereās some DB stuff too
for example, letās say Laravel
offers its own ORM
, which I understand is for OOP programming but perhaps thereās something similar approach in Clojure too?
Will clojure compiler optimize stuff like (let [a (-> foo :x :y :z) b (-> foo :x :y :q)] ...)
by noticing common expression?
@bronsa I sure do! ā¤ļø compiler tech. About the common expression. I wonder is that something that JVM could optimize later onā¦
mhh, i don't know, that would require some hardcore purity analysis which I don't think hotspot does
if those expressions are actually like what you're doing then the cost of it not being "optimised" is likely close enough to zero
(let [thing {:a {:b {:c 3}}}]
(time (dotimes [_ 10000000] (-> thing :a :b :c))))
"Elapsed time: 282.271115 msecs"
@nooga the best way to find the answer to a question like that is to use no.disassemble https://github.com/gtrak/no.disassemble
@bfabry oh, cool
the inline caches are there so that if you're doing keyword access on a record, it'll get optimized into a direct field access
no.disassemble helps too š
heh, I have to admit that I almost never care about optimizing anything when writing clojure because everything runs fast enough āout of boxā - even stuff like async proxy that parses megabytes/s of binary from the wire, grinds huge maps and unparses them to other wire. It just warms up and does its job.