This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-11
Channels
- # aws (15)
- # beginners (55)
- # boot (116)
- # bristol-clojurians (2)
- # cider (4)
- # cljs-dev (439)
- # cljsrn (14)
- # clojure (135)
- # clojure-argentina (3)
- # clojure-czech (4)
- # clojure-italy (60)
- # clojure-russia (1)
- # clojure-spec (48)
- # clojure-uk (42)
- # clojurescript (170)
- # cloverage (11)
- # core-async (19)
- # cursive (13)
- # datomic (48)
- # emacs (2)
- # graphql (3)
- # hoplon (8)
- # jobs (1)
- # jobs-discuss (5)
- # klipse (11)
- # luminus (5)
- # lumo (5)
- # mount (48)
- # off-topic (96)
- # om (17)
- # onyx (14)
- # parinfer (30)
- # protorepl (1)
- # re-frame (90)
- # reagent (2)
- # remote-jobs (1)
- # spacemacs (12)
- # specter (20)
- # uncomplicate (1)
- # untangled (65)
- # vim (2)
- # yada (8)
Is there some kind of shortcut for programmatically associating a symbol with it's same-name key? Sort of the inverse of {:keys [a b c d]}
, instead of having to type {:a a :b b :c c :d d}
to create a map.
there's a macro in flatland/useful that does that https://github.com/amalloy/useful/blob/develop/src/flatland/useful/map.clj#L9
and it's totally legit to just copy/paste one function from that lib if you don't need the rest IMHO
Thanks, just what I was looking for
@tjscollins or zipmap?
No, zipmap still requires you to write you your keys. I was looking for something equivalent to JS's {a, b, c, d}
notation which produces the equivalent of {:a a :b b :c c :d d}
The keyed macro in flatland does exactly that.
With the macro (keyed [a b c d])
becomes {:a a :b b :c c :d d}
@schmee @hiredman Iβm the author, but frankly speaking, havenβt used it for long π can we solve this?
@razum2um looks like you'd need exclusions in there to avoid certain sym
values (any primitive Java type symbols)
I am new to clojure-api. I develop small app using clojure-api. I have done DB connection, Logs capturing mechanism in my APP. I need help in exception handling mechanism. Is there any library to catch exception all types of exception and to send exception to developer mail?
@srinidagda A Google/Bing search reveals lots of Clojure wrappers for SMTP mail but, to be honest, I'd just use javax.mail directly. It's not hard.
@seancorfield Okay. Thanks for quick reply.
Sending email to developers every time you get an exception is... less than best practice... You could cause a denial of service attack on your own email provider if you app goes wrong. I definitely would not recommend that approach.
@srinidagda we use http://sentry.io for such exception capturing purposes... and there are many similar services out there
@mccraigmccraig, @seancorfield Okay. Thanks for valuable suggestions.
Is there a way to tell lein repl
to not go check the dependencies? (if I have no internet or the artefact server is down?)
export LEIN_OFFLINE=true && lein repl
seems to work.
Tried lein -o repl
and lein repl -o
but they still seem to go look for dependencies
@nha, do you have SNAPSHOT dependencies in your project.clj?
@nha, you can pin SNAPSHOT deps: https://www.martinklepsch.org/posts/maven-snapshots.html
@kunzler looks great as a series of forms typed into the repl. For me the next step would be to copy it to a file and refactor into functions. Idiomatic clojure meant for .clj files (i.e. not typed ad hoc into a repl) eschews dynamic def
s
in this case, it could look like this:
(let [cc (read-line), startswith (first cc), credit-card (case ...)] (println "credit card:" credit-card))
(of course you shouldn't type it all in a single line, I was too lazy to use an editor)
@pesterhazy thanks for that. I'm stuck on a my chromebook using an online repl So I think I'll have to try it on an editor later. I appreciate the insight
ah nice, which online repl do you use?
nice!
it's quite fast
It's been a bit rough learning clojure. Probably because it's new enough that there aren't as many resources available compared to other languages
@kunzler did you look at http://www.braveclojure.com/ ?
https://www.reddit.com/r/Clojure/ also has a nice list of resources
if I want to implement an n-node tree structure in clj, where each node can be one of a few different βtypesβ, and wanted to use spec to describe the data. whatβs a good option for polymorphism on the standard tree functions?
1) define a node that can be one of (s/def ::node #{:node/a :node/b :node/c ...etc})
, and each node has a corresponding spec and defrecord
. these records all implement some sort of INode
protocol for insertion, lookup, etc.
2) define a node thatβs a simple map with a :type
property. standard tree functions will all be multimethods dispatching on the type of a node. define a more generic spec that uses a lot of (s/multi-spec)
.
3) β¦ ?
lwhorton: 2) map and multimethod dispatch on some key. any code can consume nested maps and mutate it conforming to the spec. I would avoid the 1) OO trap
unnecessary bundling data + behaviour.
generally, it's useful when 1) you're interop-ing w/ java (so you can use extend-protocol
and do type-based dispatch) 2) you create a protocol + record to manage state lifecycle
otherwise, if you're just manipulating data (not state), simple data structures + the ad-hoc dispatch available w/ multimethods works nice and is more flexible/open
in other words... type-based (in Clojure case, actual Java types) dispatch = nominal typing, ad-hoc dispatch = more like structural typing
the problem iβm trying to model is a hierarchy-tree with directories, files, drives, etc.
What's a good lightweight way of managing configurations in a clojure project? Like environment type stuff? Urls, user/passwords, etc?
" Expresso makes great use of clojureβs abstraction mechanism like protocols and multimethods and uses a datadriven approach where possible." what does "datadriven" mean in this context? π
to me, data-driven means that the most fundamental abstraction in your code is just clojure's data structures, rather than functions, or macros, or protocols, etc
your program is controlled and organised in terms of data, with map
, assoc
and so forth being your tools of choice
http://www.lispcast.com/data-functions-macros-why
http://blog.cognitect.com/blog/2016/6/28/the-new-normal-data-leverage
you could say that datascript and datomic are data-driven databases, compared to something like MariaDB
there's also this interview with Rich - https://gist.github.com/rduplain/c474a80d173e6ae78980b91bc92f43d1 (ctrl-f for "information")
Hey @U61HA86AG , thanks for the links
Sorry for the late reply, I took some time to read the articles. I think I get the gist of what is meant by data-driven. I never learned Object Oriented design patterns anyway, so its hard for me to contrast what I'm doing in clojure against say, java.
I am curious about the following, isn't creation of a record and association protocols a more object oritented, less data-driven approach?
For example, a data-driven approach to me would just be an associated map. Maybe it has a type keyword. I can write a function which looks up :type in the map and does something with the corresponding value
whereas creating a new record seems similar to creating a new object, and writing protocols seems to me to be like creating methods
i find it hard to reconcile my use of records and protocols with a data-driven approach
can you explain?
yes, you have that correct. Protocols and Records arent simple data-types, you should only use them when you need something more abstract/powerful/clear than simple data-types can offer
Records and Protocols exist for a reason, the key is to use them when they make sense and are needed, but to use simple data as much as you can (within reason)
see here https://clojure.org/reference/datatypes#_why_have_both_deftype_and_defrecord
@aymat316 https://github.com/juxt/aero is pretty good
https://github.com/tolitius/cprop is another option
@fenton it is clear and you will find different opinions on this as itβs largely a question of style and idioms. personally, I would either pass in the valid users:
(defn valid-user? [users username password] ...
or, close over them and return a function:
(defn valid-user-fn [users]
(fn [username password]
stylistically, I donβt like the threading macro as youβre not really transforming a piece of data, threading it, as itβs often used. Iβd prefer some
:
(defn valid-user-fn [users]
(fn [username password]
(some (fn [{u ::user/name p ::user/password}]
(and (= u username)
(= p password)))
users)))
(defn valid-users
[username password]
(->> users
(map (juxt :user/name :user/password))
(some #(= [username password] %))))
Now you can make your function:
(let [valid-user? (valid-user-fn master-users-list)]
;; now use valid-user? as you wish...
(if (valid-user? "bob" "abc123")
...
and if you want to use a different set of username/passwords, youβre not tied to any particular one. just make the new valid-user?
function by calling valid-user-fn
with your list@zetafish @joshjones thanks this is what I was looking for... both great suggestions. @bfabry lol, right not a real system...lol... just creating an om-next tutorial, so just for edification purposes! π
Is this a bug?
(defn callable
[fun]
(proxy [clojure.lang.IFn] []
(invoke [& args] (apply fun args))))
((callable +) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18) => 171
((callable +) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)
1. Unhandled java.lang.UnsupportedOperationException
invoke
@rinaldi I guess this works (if you have memory) (-> stream slurp .getBytes alength)
otherwise use
@bfabry Yeah, that does sound weird. What I am doing now is: 1. Make an HTTP request and get back a JSON file 2. Convert that to a ZIP file (gives me back an input stream) 3. Need to know the size of this payload
@hlolli i think you're running into the limitation that you can only have 20 arguments to a function
and i 've heard someone talk about "trivial" functions through the repl are not invoked in the same way as normal functions
@rinaldi are you're trying to determine the file size to send on the response?
any hacks to bypass it? It's a bug in overtone
, changeing the implementation where this is defined would be pain
@hcarvalhoaves Precisely. I'm trying to do all these steps without performing IO.
i'm way out of my depth on that one. I think @hiredman or @noisesmith would know way more than me
@rinaldi you would have to hold all response in memory, use a buffered reader + this instead -> http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.3.6.1
otherwise you have to make sure you don't OOM π
I am sending this payload to S3 and one of the requirements is to pass in the content length alongside the payload
maybe proxy does sort of support that, I am not sure, depends on how you read the docstring, but I have never read it has supporting that
https://github.com/overtone/overtone/blob/master/src/overtone/helpers/lib.clj#L146 here when the range is changed I bump into the same error as I posted above.
I was going to say, that is defrecord which is a different beast entirely from proxy
no, I mean, those are all interfaces it is proxying so reify is likely a better choice
I am not familiar with the codebase, but from scratch I might prefer to pass around a map with a key that maps to a function
the issue is, the last arity of invoke needs to call applyTo, or something like that, you should check out AFn.java
there are invoke arities from 0 to 21, the 21st arity takes 20 args + an array as the 21st
I see what you mean, but I can't see how that would be implemented. It's macroexpanding to a argument pyramid of invoke.