This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-10
Channels
- # admin-announcements (1)
- # alda (1)
- # bangalore-clj (1)
- # beginners (94)
- # boot (139)
- # braveandtrue (1)
- # cider (19)
- # cljs-dev (21)
- # cljsjs (8)
- # cljsrn (79)
- # clojure (124)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-berlin (3)
- # clojure-hamburg (3)
- # clojure-quebec (1)
- # clojure-russia (77)
- # clojure-spec (5)
- # clojure-uk (18)
- # clojurescript (39)
- # conf-proposals (21)
- # core-async (5)
- # cursive (8)
- # datomic (40)
- # defnpodcast (1)
- # devcards (14)
- # dirac (5)
- # editors (1)
- # emacs (4)
- # jobs (1)
- # liberator (4)
- # onyx (29)
- # perun (15)
- # proton (15)
- # protorepl (9)
- # re-frame (47)
- # reagent (38)
- # ring (1)
- # rum (7)
- # specter (23)
- # untangled (8)
- # yada (55)
as opposed to this working-but-verbose example:
(let [m #::my-ns {:a 1
:b 2
:c 3}
{:keys [::my-ns/a ::my-ns/b ::my-ns/c]} m]
[a b c])
Wait, does (partition 0 [1 2 3])
really just hang?
Or rather, I support forcing it hangs, because it produces an infinite seq of empty seqs?
Well, that’s my first contribution to http://clojuredocs.org, I was really surprise by that, and accidentally hung my browser for a minute 2–3 times there.
@porglezomp: looks like, specifically, it hangs because this would always evaluate to true https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L3065
Yeah, it makes sense just from a “consume all the pieces” point of view.
If you take nothing off, you’ll never get all the way through the collection
even (count (take 0 :not-a-coll))
is 0
So, I accidentally became the maintainer of cloverage, and I’m trying to figure out how to add cljc/cljs support (hoping it won’t be quite as bad as it looks). It’s been around for a while, so I’m not sure if parts of it could be obviated. For example, is there something like ztellman/sleight (ideally managed as something part of clojure) that does “read, but modify before using” — in this case, for adding coverage instrumentation?
cloverage is growing features like “try to read cljc if clj fails” — which feels like behavior cloverage shouldn’t implement itself, because it can only mimic clojure (best case: more code to maintain; worst case: it gets it wrong in a way that affects coverage results)
@lvh you could take a look at https://github.com/hilverd/lein-ns-dep-graph
I think tools.namespace will become your friend here
@danielcompton: Thanks! I’ll make sure to look at that more closely
newbie question: (Math/pow 5 2) ; works but (fnil Math/pow) nil 2) ; gives unable to find pow in Math
Can anyone comment on why function signatures look the opposite in core clojure functions, like map vs select-keys? In map (or other h-o fns), the first arg is typically another function, followed by a seq; in select-keys and other similar fns, the order is turned around. This still confuses me and I often have to look up the docs, as I can’t write ->> or -> fluidly. Any comments, appreciated.
Because of this intentional split in arg ordering, data structure or collection functions work well when chained with -> and sequence functions work well with >>
It's generally not common to be doing both in the same threading chain but if so, as-> can sometimes be helpful
@atroche: you will be interested in the new namespaced key destructuring in Clojure 1.9 - see http://dev.clojure.org/jira/browse/CLJ-1919
@xcthulhu: yes, this is a known problem http://dev.clojure.org/jira/browse/CLJ-1790
@alexmiller: perfect, thanks 🙂
thanks @alexmiller. I need to use more of as->
@bhagny control over the namespace map syntax during printing is coming http://dev.clojure.org/jira/browse/CLJ-1993
Someone has suggested a patch to cloverage that rewrites into, empty and walk because the original versions don’t preserve metadata. Is that the best way to get metadata to be preserved? https://github.com/lshift/cloverage/pull/72/files
Program transformation based on walk has always struck me as kind of, uh, hinky I guess is the word
@lvh: Not sure what you need those functions for but specter has a walker that preserves metadata: https://github.com/nathanmarz/specter/wiki/List-of-Navigators#codewalker
@hiredman: hm, right. that lib already uses riddley so maybe we should just port it to that
How to write this one in cljs ? "SivaKumar25689".match(/[A-Z][a-z]+|[0-9]+/g).join(" ") => "Siva Kumar 25689" or how to split a string at Capital letter in clojure script ?
way verbose.. but (->> "SivaKumar234" (re-seq (re-pattern "([A-Z][a-z]+)|([0-9]+)")) (map first) (clojure.string/join " "))
should work.
@gnejs: thanks its working.
@sivakumargsk: Somewhat less verbose version
(->> "SivaKumar234"
(re-seq #"[A-Z][a-z]+|[0-9]+")
(str/join " "))
@sivakumargsk: (clojure.string/join " " (re-seq #"[A-Z][a-z]+|[0-9]+" "ManishKumar123"))
Hey folks, got a dumb question. Is it possible to print out the contents of a transient vector
My guess is i would have to convert it to something else and print it, then convert it back?
Most likely, yes. Printing is a side effect and transients aren’t meant for side effects.
You can grab elements via get
while transient so you might be able to use something like for
to generate side effects but that would really circumvent what transients are there for.
Thought I'd share this amazing blog (ton of interesting Clojure projects). It's mainly embedded stuff but though it was worth a share. https://nakkaya.com/tags/#clojure
@herbm im not sure how fnil works with more then one argument.. ((fnil name "") nil)
> (doc fnil)
-------------------------
clojure.core/fnil
([f x] [f x y] [f x y z])
Takes a function f, and returns a function that calls f, replacing
a nil first argument to f with the supplied value x. Higher arity
versions can replace arguments in the second and third
positions (y, z). Note that the function f can take any number of
arguments, not just the one(s) being nil-patched.
Hey all... I can't really see this anywhere but I thought I'd ask. I'm hoping to use clojure.tools.cli
to parse some command-line arguments that are in the form --define key-name value
but I don't see built-in support for it, am I missing something?
I'll probably just wind up using a --define key=value
syntax, just wanted to see if there's a good alternative before I write it
@timgilbert, not sure about clojure.tools.cli
but you could easily parse that yourself. If all of your arguments are in that format, use (partition 3 …)
. If you have other style arguments, just move through the argslist and check for the argument type you’re expecting and then take the next one or two arguments and process that little chunk.
@timgilbert: depending on what you are doing, you should check out boot. It comes with a macro called defcli
that handles cli arguments, defaults, and help text.
Hmm... I'm using leiningen and I have a bunch of other stuff tied into tools.cli already, I think I'll probably just wind up parsing it myself with the :assoc-fn
stuff. Thanks though!
@jswart: Nice to know, I've been doing a lot of work with tools.cli
lately and was looking for an alternative.
Yeah I’m a huge boot fan. Project configuration as a program that you control is nice. It gives you a few abstractions and then gets out of the way.
@yonatanel: I don’t think I ever considered the idea that you could apply a new configuration on top of an existing system. I would not do it … component and config work well enough that you should discard the entire stopped system and just create a new one. I don’t use the reloaded workflow since I use Cursive, which does a lot of the interesting parts for me.
When I’ve been doing more active server-side development (web services with Rook) a key part of my arsenal was a special filter that, on every request, rebuilt the Rook dispatch table for the request, allowing changes to functions to be picked up.
I hope to provide something similar, but for Pedestal, with Rook 2 (which is Rook’s meta-data driven namespaces and functions as a thin layer on top of Pedestal).
hi guys
I’ve found that code inside protocol methods is hard to debug (or even set breakpoints on) inside Cursive, so my protocol methods are usually a thin layer around a more-pure function.
what is the best way to get random number between range, i know there is rand-int, but i want to get float also?
rand work from 0 to limit you specify
what about from -1 to 1 ?
for example
(-> [(rand 1) (rand -1)] rand-nth)
dg what do you think about this?
(defn rand-float [min max] (-> [(rand max) (rand min)] rand-nth)
(- (rand 2) 1)
or generally (+ (rand (- max min)) min)
That would work, though I'm not sure if the probability distribution is truly the same. What I posted is a more general solution.
dg: thanks man
@abdullahibra your happens to give a good distribution for (-1 1) but in general it could give you stuff out of range
e.g. (rand-float 10 11)
optiona metadata, doc strings, multiple arity parsing, and more
All made worse by the imperative macro parsing.
a lot of it is just untangling the args so that it knows what you've given it, because many args are optional, and the args are positional
That let-rebinding is interesting to me. Makes sense as a way to break down transformations in sequence.
yeah. tbh never seen that before 🙂
be interesting to see how using core.spec to parse args instead would differentiate this impl
it'd be much easier
but I doubt that cleanup will ever happen because clojure.spec needs defn to exist already :)
also that’d make a hard dependency on spec where you don’t need one. it’d be an interesting experiment though to redef defn and see how it works
yeah. i don't think we'd ever get one, but it'd be nice to see what the difference would be
alot of macros are tough to read because of this positional parsing
uses up all your short term memory slots 😛
oahner: yes, part of 1.9
I swa this (http://wiki.call-cc.org/explicit-renaming-macros) the other day, which looks like an interesting way to bootstrap other macro systems
@oahner: it is part of standard lib, it’s just not required by default. I thought it was a contrib-esque lib like core.async
it's part of the jar because of the integration with doc, and all the improvements to predicates and stuff
e.g. we finally have boolean?
less well known is the new map reading/printing syntax, for maps with namespaced keys: http://dev.clojure.org/jira/browse/CLJ-1910
anyway, if you really want to use spec to parse things, without having a runtime dependency on spec, write a spec compiler instead of an interpreter
speaking of spec and namespaced keys, am I to understand that it's good practice to namespace all keywords that might be used as a key?
all keywords that'd have a spec, possibly
although there's req-un and opt-un
lots of existing code and data out there!
Anyone know how to hover over something using semperos?