This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-05
Channels
- # admin-announcements (10)
- # beginners (18)
- # boot (29)
- # capetown (2)
- # cider (46)
- # cljs-dev (1)
- # cljsrn (69)
- # clojure (126)
- # clojure-android (9)
- # clojure-gamedev (3)
- # clojure-greece (16)
- # clojure-poland (13)
- # clojure-russia (45)
- # clojure-spec (27)
- # clojure-uk (21)
- # clojurescript (99)
- # cursive (1)
- # datascript (1)
- # datomic (42)
- # functionalprogramming (10)
- # hoplon (47)
- # instaparse (12)
- # jobs (5)
- # jobs-rus (9)
- # keechma (22)
- # lein-figwheel (8)
- # leiningen (5)
- # luminus (1)
- # mount (7)
- # off-topic (1)
- # om (15)
- # onyx (47)
- # other-languages (14)
- # planck (28)
- # proton (8)
- # re-frame (30)
- # reagent (15)
- # remote-jobs (3)
- # slack-help (2)
- # untangled (9)
- # yada (6)
I have question about clojure.spec: Can the error messages reported by explain be customized ? I’m trying to use spec for validation
do you mean something like using explain-data
and then mapping the returned data structure to some of your own messages
@macroz: I don’t want to map the returned data structure to my messages. Instead I would like to define custom messages at predicate level itself
Is there a way to see if a future is failed? I can see it when I print it out: #future[{:status :failed, :val #error {
but I couldn't find a failed?
function
@brao I find that always the app that actually shows the error message to the user must contain the mapping, the service can only return some kind of data that describes the error
therefore the actual (localized etc.) message and logic must reside in an app somewhere
yes, pretty straightforward. I need to do things like - check if some keys exist in a map, they’re of the expected type and so on.
I have always made the validation -> error message mapping by hand, not trying to implement a clever system with "typing"
suppose I have a map in which a expected key is missing - explain
gives me the predicate that failed - and it’s a partial function made out of contains
yes, spec looks very promising. If only, at each spec level, I could also put some human readable message to report when validate failed, it would be perfect for what I have in mind
@escherize: we haven't even started working on Clojure/west 2017 yet, so no. Also FYI there is #events
@brao there is no facility in spec to customize errors other than taking the explain-data and producing what you want from it
@pesterhazy: all the future related functions start with "future-" if you check the docs
@alexmiller: okay, but having it would be quite useful isn’t it ? Do you suggest any other way to do such a thing, other than interpreting explain-str ?
@alexmiller: is there a chance something like this will come in a future release ?
@alexmiller: there's future-done
, but it looks like there's no way to retrieve the future's status (whether it failed with an exception) other than deref'ing it
The output of explain-data is data - it's designed for this and sufficient
Right now, I don't think anything more will be added
@alexmiller: okay, thanks!
@pesterhazy: is there some reason not to deref it? Don't want to block?
The thing you get back from a future is a java.util.Future so check that api too
@macroz: that's what I tried to figure out (what prints the #future
string)
I guess it's this: https://github.com/clojure/clojure/blob/99d10ceb26a3078698a5b970a912ed88f95e688a/src/clj/clojure/core_print.clj#L414
right, that's fine (that's what printing does as well)
so I'll do it similarly then:
(defn failed? [fu] (try
(deref fu)
false
(catch Throwable e
(log/error "Cached function previously failed:" e)
true)))
Is there a better way than
(read-string (str "'" &form))
to get the entire body of a macro call? I'm trying to put the entire body of the macro (as data) into the Metadata of the defn that it evaluates to. @mjhamrick:` '~&form
@mjhamrick: http://stackoverflow.com/questions/37998686/why-does-this-clojure-macro-need/38000404#38000404
@mjhamrick: that's just a fancy way of writing (list 'quote &form)
I’m having trouble thinking of the right way to approach a problem of transforming a nested tree structure. I’m wondering if maybe this is a time to reach for a zipper (never used them before so this might be shiny object syndrome) or missing some simple insight? My thinking so far involves a lot of finding indices and vector management suggesting I may be missing more Clojure way of thinking about this. I’ve written up the details https://gist.github.com/mmower/3cd21f55a80fa335b0fbd2defdf331a1 and would appreciate any thoughts.
@sandbags: zipper seems like a pretty good option. Also take a look at zip-visit, could simplify some of your logic if you do end up using a zipper: https://github.com/akhudek/zip-visit
haven't thought about your problem that hard but definitely seems like a vector zipper would fit the bill: https://clojure.github.io/clojure/clojure.zip-api.html#clojure.zip/vector-zip
@ddellacosta: thanks for the pointer, i wasn’t sure if i was reaching for an over-complicated tool
on the contrary, think this is a way to simplify the problem
ah, zip-visit appears to answer my first question about using a zipper for this purpose (in that i have to manage some state)
@acron: might be worth asking this in #C051WKSP3 channel?
thanks @agile_geek
@acron: np! See I'm still a help even after I've come back off busman's holiday!
hi, noob question, but how to put semicolon as character ? for instance to pass it as :separator in read-csv fn ?
user=> (csv/read-csv "foo;bar" :separator \;)
(["foo" "bar”])
@kosecki: you're passing a sequence to read-csv
--it should be either a string or a reader
@lopalghost: yep you are right, just noticed that when run in lein repl, proto-repl has some issues with semi-colon apparently
@kosecki: can you try putting it in quotes? ";"
I'll file an issue against Proto REPL for this.
Just FYI, i also run into problems with specific "exotic" character literals. You can resort to (char xx) anytime, with xx being the ASCII code. \; is (char 59)
does anyone recall seeing a project recently announced for persisting edn data to postgres?
@jasongilman: read-csv expects Character, error when passing the String
what would be the best way to take a vector and then return a hash-map that maps the values of the vector to their index in the original vector?
(into {} (map-indexed vector v))
oops, that would be the opposite (mapping indexes to their values)
@aengelberg: that’s quite elegant looking. thanks! i figured clojure had a nice way to do this.
@ezmiller actually it's more like this:
(into {} (map-indexed (fn [i value] [value i]) v))
or even better:
(zipmap v (range))
yay zipmap 🙂
What is more elegant way to update vector item that satisfies a criteria? I know that I could use classic map for this but I'm searching for a method that don't naively iterate through all items but rather implement some smart search for a item using criteria.
http://github.com/nathanmarz/specter may do what you want. what kind of criteria?
(def data
[{:id 1 :a 1 :b 2 :c 3} {:id 2 :a 11 :b 22 :c 33} {:id 3 :a 111 :b 222 :c 333}])
I wanna UPDATE data SET :b="changed" WHERE :id=2
(use 'com.rpl.specter.macros 'com.rpl.specter)
(setval [ALL (pred #(= (:id %) 2)) :b] "changed" data)
pardon me, live-editing my code as I see new mistakes 😉
Specter looks nice at the first sight... I think that I saw it somewhere... Thanks. 🙂
@aengelberg @novakboskov you actually don't need the pred
, Specter recognizes anonymous functions and inserts it automatically. So you can write that as:
(setval [ALL #(= (:id %) 2) :b] "changed" data)
let’s say I want to have a fn that imports data fro a csv that other fns will then work with (not mutate). what would be a sensible way to do this in clojure? can a fn load something into a global space of some sort?
@nathanmarz: Thanks! Are there any examples that shows how to jack in it into clojurescript?
you just need to do refer-macros on the com.rpl.specter.macros namespace, otherwise it's the same
(require-macros '[com.rpl.specter.macros :refer [setval select transform]])
(require '[com.rpl.specter :as s])
(transform [s/ALL :a even?] inc [{:a 2 :b 1} {:a 3} {:a 4}])
;; => [{:a 3, :b 1} {:a 3} {:a 5}]
@nathanmarz: Really cool! 🙂
@ddellacosta: do you know the rationale for, for example, clojure.zip/right returning nil rather than :end when you go off the edge?
@sandbags: :end
being some kind of token that you just used as an example of something it might return in that case? I don't see that in the docs otherwise
I would assume that is just so it matches the usual Clojure semantics for figuring if there is a value there or not
unless I don't understand your question
@ddellacosta: ah, i’m confusing the return value with the internal value in the zipper that end? uses
I suppose what I am really asking is why right et al. don’t return a valid zipper where (end? z) => true rather than nil
but i’m still trying to grok them, maybe there’s a perfectly reasonable reason for it
Anyone happy with a library that makes it easy to post to insecure https?
(this is a client app for a testing tool that has to target this as well)
@sandbags Okay, I had to give myself a little refresher in clojure.zip to be able to understand what you were asking
I think the thing here is that you need clojure.zip/next
to traverse depth-first, per the docs, and the :end
token (I see it now) which I guess is what end?
is reading only occurs at the end of that
if you use right
it's not going to behave the way you're expecting
I'm scanning the original paper now (https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf?cm_mc_uid=64539085903114677514600&cm_mc_sid_50200000=1467751460) but not seeing an analog for the next
function
@ddellacosta: yes, you have it .. i guess i didn’t see why the rules should be different for right/left from next
@mj_langford: Pretty sure I've used clj-http for that same purpose without any real problem. https://github.com/dakrone/clj-http#post Feel free to dm me with more specifics if you run into any problems.
if I have a java method that expects an object implementing interface FooRunnable, is there any way I can "extend" clojure.lang.AFn to appear as if it implements this interface?
rationale: that would allow me to pass (fn [] …)
as the argument to that method, rather than a reified object implementing FooRunnable
Loving how quickly all the Clojure 1.9.0 Alpha builds are coming out! We have Alpha 7 in production, Alpha 8 on QA, and Alpha 9 in DEV right now as we’re already leveraging some of the new predicates and just committing our first code built on clojure.spec
!
that’s awesome @seancorfield