This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-27
Channels
- # admin-announcements (1)
- # beginners (1)
- # boot (37)
- # cbus (1)
- # cider (44)
- # cljs-dev (16)
- # cljsjs (2)
- # cljsrn (18)
- # clojure (205)
- # clojure-belgium (6)
- # clojure-china (1)
- # clojure-india (1)
- # clojure-russia (24)
- # clojure-spec (21)
- # clojure-turkiye (1)
- # clojure-uk (72)
- # clojurescript (91)
- # core-async (4)
- # cursive (12)
- # data-science (2)
- # datascript (2)
- # datomic (12)
- # emacs (6)
- # flambo (7)
- # funcool (12)
- # hoplon (24)
- # incanter (2)
- # jobs-discuss (29)
- # keechma (2)
- # lein-figwheel (2)
- # leiningen (2)
- # mount (13)
- # nyc (2)
- # om (76)
- # om-next (1)
- # onyx (38)
- # other-languages (4)
- # planck (40)
- # re-frame (33)
- # reagent (101)
- # ring-swagger (5)
- # slack-help (1)
- # untangled (7)
- # yada (14)
What exactly are :exclusions
in a clojure project dependency list? Is there a good blog post or document that explains it?
@danburton they exclude transitive dependencies
lein deps :tree
will show you the tree
exclusions let you chop parts of that tree (below the top)
and searching for "maven dependency exclusion" should find you similar things if you can make the translation
Exclude them from what? How can that dependency function if I cut off one of its dependencies?
well two common reasons
exclude from being part of your classpath
sometimes two things you include both include different versions of the same dependency
and then you need to iron that out - they will both be on your classpath, but the classpath is linear so one will shadow the other (and which that is is somewhat arbitrary)
look up "lein pedantic" on how to have it detect these (potential) problems
the second case is that a lib includes a dependency that you know you won't need - either because their deps are buggy, or you're not using the features that need that lib, or something else
i wanted to ask you if there is an implementation of a map similar to json's concept. I need repeating keywords. Is this possible?
@vandr0iy: not sure i follow - how can a map have repeating keys ? what would getting from that map look like ?
I'd like to represent in memory an object - similar to json - that has a couple of repeating keys. Not exatly a map, though
@vandr0iy: if what you need is multiple values for a key, you can represent that with a vector of values for each key or similar
@vandr0iy: fnil
can help make updating such a map easier - e.g. (update {} :key (fnil conj []) :val)
@mccraigmccraig: thanks
no, if they really are constants
for example: I find myself implementing a function that uses a particular array of values (it's a pattern of movement of a pawn in a game)
if they are pragmatic constants (i.e. they are helping you develop now, but are likely to become parameters later) then you could try and make as many of your functions as possible pure (i.e. take the values as params) and wrap them in a layer of impure functions which refer to the globals
They are fixed constants, that will never change. I'm implementing a challenge relative to chess, and I needed to save a couple of patterns in order to remember them and not reinstantiate them every time a function is fired (it's a combinatoric challenge, so it will happen very often and it has to eat as little memory as possible)
hi guys
is there anybody tried flambo?
There is a #C0BV9GEN5 channel which you might find useful
Does anybody know where does tools.nrepl
dependency comes from in leiningen
projects?
I removed it from profiles.clj
and from project.clj
but lein deps :tree
still shows me tools.nrepl
as it has been required on top level.
lein repl connects to the jvm process through an nrepl, doesn't it?
Ah, so there is some tool.nrepl version that is shipped with leiningen.. Clear now. Thanks @pesterhazy
@danboykis: I am porting a bunch of schema to spec right now to become familiar with it
The experience so far has been nice!
@crimeminister: I am not sure how to structure my specs yet, this is a pretty large nested map (my config file is edn) and it's kind of a pain so for example
{:io {:http
{:ignore-ssl-auth? true
:pool {:socket-timeout 600000
:conn-timeout 600000
:conn-req-timeout 600000
:max-total 500
:max-per-route 500}}}}
Probably easiest to start by creating a spec for each attribute (it's The Spec-ish Way)
Then specs for each sub-collection
And keep repeating that process until you reach the root
To start
Can always refine the specs to tighten them up
I was in a similar boat
Ended up creating a "core" namespace for shared attributes
Most everything else was defined in nested namespaces reflecting the data structure being spec'ed
Mainly because of the sheer volume of specs
Wouldn't bother for a less hairy set of data types
What do you mean by wishing it was declarative?
(spec/keys :req-un [::io])
(spec/keys :req-un [::http])
(spec/keys :req-un [::pool] :opt [::ignore-ssl-auth?])
(spec/keys :req-un [::socket-timeout ::conn-timeout ::conn-req-timeout ::max-total ::max-per-route])
I wish I could say
{:socket-timeout integer?
:conn-timeout integer?
:conn-req-timeout integer?
:max-total integer?
:max-per-route integer?}
The rationale document is worth a read if you haven't already
It is reminiscent of Datomic
I find that reassuring 😁
I have already started to adapt to the idea of using namespaced keywords
Stick with it, you might like it!
My take is that the resemblance that schemas bear with the actual maps is more appealing to the eyes - but I might be biased too due to being very used to schema
Schema also feels more "pure", it's just values you compose, no state (arguably declaring type could be considered as such, at least compared to putting stuff in a registry)
Interesting, as a Datomic user it felt quite comfortable right away to me
That’s interesting - Datomic user here too but don’t really feel the same
My problem is not with namespaced keys, I like them - it’s more with the syntax for declaring specs
Or perhaps I need something to click before fully comprehending. Gotta try spec out...
mpenet: the registry is there for edn's sake, you can't eval clojure symbols like code can
yea, I saw the word 'evalable' being used, so it seems like it's best to stick with core functions if you're going to distribute/transmit specs
I would guess that if you need to do that kind of stuff you'd have control over this. Same problem applies to other schema/contract systems
Trying to do a simple base64 encoding actually and it seems like something needs to be pulled from clojars
There's a core lib that needs to be added to project.clj, which how would one achieve from the repl directly?
@cmcfarlen: the installation section of the readme mentions that pomegranate must be added to project.clj, can it be used as a plugin instead?
Will be dabbling more and I believe will find this very useful as I will discover new libraries to try out
And this too which I haven't tried: https://github.com/pallet/alembic
@cmcfarlen: refactor-nrepl looks useful, and alembic is built on top of pomegranate. Tried pomegranate and it indeed works. Successfully fetched the library from the network and loaded it to the classpath.
Hello all, I am trying to make some async calls and getting this exception No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: clojure.lang.PersistentList
@mpenet @danboykis @viniciushana On the off chance anyone is interested, I think I will use this as my repo dumping grounds for potentially re-usable specs: https://github.com/clojurist-ca/clj-specs
@crimeminister: i'll take a look, good idea!
@danboykis: not much there yet, but maybe it will grow. Feel free to contribute anything you feel others might have use for!
Anyone ever used Pollen (a typesetting language/system in Racket for HTML & other things)? I'd like to try to make something really simple based on that in Clojure, where, in essence, a string like "◊[:p hi there ◊[:b Ahmed]! How are you?]"
gets turned into a Hiccup/HTML vector [:p "hi there " [:b "Ahmed"] "! How are you?"]
. The first roadblock towards this is how to parse a string, character by character, waiting to get a complete Clojure expression?
so, banging my head against the wall trying to figure out how to get a basic Slack integration via Incoming WebHooks working using clj-http. I can run their curl example just fine, but when I use clj-http and pass in the information via :form-params {:payload (json/generate-string msg)}
then I get missing_text_or_fallback_or_attachments
. Same for :body (.getBytes (json/generate-string msg))
. Has anyone tried this before? Seems like I’m doing something really obvious wrong but I’m completely confused as to what that is.
@fasiha: haven’t used pollen, but for parsing, check out https://github.com/Engelberg/instaparse
FWIW the slack docs say: > You have two options for sending data to the Webhook URL above: > > Send a JSON string as the payload parameter in a POST request > Send a JSON string as the body of a POST request
nevermind
Here's what I'm using:
(post [webhook-url text]
(client/post webhook-url {:form-params
{:payload (json/generate-string {:text text})}}))
@zmaril you hit my achilles’s heel—I have no idea how parsing/grammar works 😛 hitting the books…
fasiha it’s pretty simple, spend a bit getting the hang of BNF and you’re good to go
instaparse makes it easy
bet you’ll find yourself writing up a grammar in no time
@ddellacosta: I should study BNF first/simultaneously with Instaparse? Not just try and go to Instaparse directly?
@fasiha: I would start playing with instaparse right away
as I think he gives a bit of an introduction in the docs
Try this? http://gigasquidsoftware.com/blog/2013/05/01/growing-a-language-with-clojure-and-instaparse/
and you can fill it out as you need to
or yeah, there’s that 😄
@zmaril: reading that, and a couple of other google results now. I'm getting a little worried looking at these examples at having to write a grammar for Clojure code tho?
either way, don’t think you’ll need to go back and read a book/take a course or anything that intensive
you can definitely pick it up pretty quickly
and it’s fun!
:thumbsup:
That one is the crazy one. Postgres docs provide a grammar in a markup language inside the source code. So I built a parser for the grammar in the docs and then generated instaparse combinators based off of that.
wow, cool stuff
in the spec
guide, one of the examples has:
(s/def ::email-type (s/and string? #(re-matches email-regex %)))
(s/def ::email ::email-type)
Is there a reason for the second definition? I don't see an obvious one.I don't see an obvious reason. I would assume it's just a poorly chosen example of how you can define one schema to be the same as another in this way.
@sashton: yes, there is a good reason!
the ::email-type spec is a reusable definition for an email attribute "type"
whereas the ::email is a key attribute expected to be used in a domain entity map
you might also have ::work-email ::company-email or whatever
by separating the part defining what an email is, it can then be reused to form the basis for many attributes
from working on some domain examples, I see this kind of split come up often - it's totally reasonable that we (as a community) could develop shared primitive specs like ::email-type that are reusable across projects (where the domain attributes may not be)
on use, spec will "chase" the keywords to find the actual definition so there is no practical difference - this is about creating reusable semantics
Can you reuse the ::email-type inside another expression? I would guess not because they are just keywords and not predicates i.e. (s/def ::company-email (s/and ::email-type #(re-matches some-other-more-restrictive-regex %)))
you definitely can
all of these compose
wrt reusability... why not this instead?
(def email-type (s/and string? #(re-matches email-regex %)))
(s/def ::email email-type)
I don't see the benefit of attaching the email-type
to that particular key, rather than just a def.@danburton: one thought I have is that everywhere you want to refer to that email-type
in other namespaces, now you've got to refer
its namespace, rather than just referring to the qualified keyword:
(require '(some.place :as place))
(s/def ::company-email place/email-type)
; vs
(s/def ::company-email :some.place/email-type)
could do either
one possible benefit would be that you could attach a custom generator to the registered version
I'm not doing that there, but I could have
then the generator would be created once instead of many times
does anyone know how to implement an empty route with compojure? (e.g. (GET "" [] handler)
)
it doesn't seem to handle this properly since it creates a regex out of ""
which becomes #""
, and this doesn't match against anything at all
Ignorant novice question: Android apps are coded in Java and Clojure runs on the JVM, does this mean that Clojure can be used to develop native Android apps?
@samuelf: In principle, yes. It's not ideal, because Clojure(JVM) load time is problematic for mobile apps, but people have successfully built Android apps with Clojure.
@fasiha: If you're parsing Clojure forms, then clojure.tools.reader might be enough for your purposes: https://github.com/clojure/tools.reader
i'm not sure, but at a minimum, you could just define a custom handler which checked that it is a :get
and the url is ""
well, i guess the url wouldn't be blank in that case. you'd have to know what the root path was, i think
I ended up writing a middleware that checks to see if :context
and :uri
values are equal on the request
nice!
instaparse is so fun to play with
My next question is—I seem to need to do char by char parsing of the strings (non-Clojure), so I get [:p "h" "i" " " "t" "h" "e" "r" "e" …]
Is there a canonical smart way to merge adjacent strings inside a vector into a single string, when that vector may contain other non-strings (which it should leave alone), including sub-vectors?
I can write a tricky & inscrutable recursive reduction, just wondering if there's either (1) a better way to merge runs of strings, or (2) a better way to parse (and I think it may be hard to improve on the parser, I messed with it a good bit, but then again, I've only been parsing for an hour)
fasiha, I'm probably missing something as I haven't touched instaparse in a while and I'm not super clear on what you're trying to do, but if you are using a regex for <string>, can't you simply adjust it to use the \w
character class with a quantifier?
@fasiha: (apply str (filter string? the-seq))
?
oh am i ignoring your earlier conversation?
Yeah this (and its intellectual parent, Pollen) is a really unusual use case. I want to use ◊
to indicate the start of a Clojure expression but things outside Clojure exprs are free text, and will eventually be surrounded by quotes (making them strings). So the string
target is for anything non-Clojure-expr (i.e., not following a ◊
), and I need to parse that char-by-char because the input could hit a ◊ at any time. Also, \w
is insufficient because the free text could literally be anything
ah you want to merge the 1 char strings while keeping them in place
@adambros: (apply str (filter string? [:p "hi" " there"]))
returns "hi there"
, but I need [:p "hi there"]
right
oooh, I see fasiha
specter might have something, let me take a look
not pretty, but can always brute force it:
(reduce (fn [acc ele]
(if (and (string? (last acc))
(string? ele))
(conj (vec (butlast acc)) (str (last acc) ele))
(conj acc ele)))
[]
[:p "foo" "bar" :bar "baz" "quux"])
;=> [:p "foobar" :bar "bazquux”]
(keep identity (specter/transform [(specter/filterer string?)] #(vector (apply str %)) data))
might not handle recursive data
ah doesnt work for
[:p "h" "i" " " "t" "h" "e" "r" "e" " " [:h1 "f" "b" "r”]]
=> (:p "hi there " [:h1 "f" "b" "r”])
could do a postwalk over all vectors and use that function
I have a problem: for some obscure reason I have to call a javascript hmm... script from clojure (not clojurescript). So I'm using clj-rhino. Everything's fine if that javascript returns a string or an integer. If I want (and I want 😄 ) to return a JSON I don't know how to translate/parse/transform it into something usable in clojure.
could return a string of the json and use something like Cheshire to parse it into a Clojure map: https://github.com/dakrone/cheshire
yeah... unfortunately I have too little control over the javascript part. must be a \"regular\" json. Or maybe Y have to wrap that javascript into another one... that's an idea