This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-22
Channels
- # beginners (122)
- # boot (217)
- # cider (14)
- # cljs-dev (74)
- # cljsrn (22)
- # clojure (101)
- # clojure-nl (4)
- # clojure-russia (22)
- # clojure-taiwan (5)
- # clojurescript (87)
- # cursive (4)
- # datavis (2)
- # editors (3)
- # hoplon (2)
- # jobs (2)
- # ldnclj (1)
- # lein-figwheel (1)
- # luminus (1)
- # off-topic (1)
- # om (105)
- # onyx (37)
- # reagent (2)
- # spacemacs (2)
https://docs.oracle.com/javase/tutorial/sound/capturing.html would you all interface directly with java to capture sound from a mic, or is there a clojure lib?
Suppose you find a great java library you want to use and not finding a clojure wrapper library extant, you decide to consider writing it yourself. Are there any guidelines that might be followed? any advice? any pitfalls to avoid?
that's actually something I would like to think about more or have someone else more familiar with the problem space chime in on.
as an example, if I just wrap calls to a Java library to make it idiomatic and nicer to use with Clojure, I still lose out on some of the niceties of doing it in Clojure and I fear with any reasonably non-trivial library it will quickly just become Java with lisp syntax and not Clojure inter-oping with Java.
Oh, I really wish people would just stop using dynamics
I would do (let [[hand new-deck] (split-at 3 @deck)] (reset! deck new-deck) hand))
depending on your concurrency story you may need to look into transactions features (out of my depth there)
Hi, here’s a bit of core.async code. I am trying to wrap a queue (a simple PersistentQueue) with a channel. Another process writes to that data-structure (using swap! conj) however, the recur doesn’t seem to pick up the next item - what am I doing wrong?
There doesn't seem to be a problem with your use of recur add some logging to see where its hanging
Hi, how do you do interactive development with seesaw? I tried a very simple snippet with a main function showing a frame (from https://github.com/daveray/seesaw) and then tried to reload it in the repl after changing the text, but nothing happened in my UI. Is there a trick to this?
Hmmm, so I don't think that's what it does. This
(= 25 ( fn[f] (f 5))
(fn [n] (* n n)))
is equivalent to this:
(defn [f] (f 5))
(defn [n] (* n n))
(= 25 fn1 fn2)
And functions never equal to anything other than that one specific function instance IIRC.
@jaen: a small specification to function equality - anonymous functions are all unique, but named functions are not. (= comp comp) evaluates to true.
@ian: yes, that's exactly what I've meant, but the way to put it is certainly more clear.
I think it has nice syntax highlighting with rainbow parens. They are really helpful - just pay attention to their colour - in your case you gobbled up the (
paren before the _
and it changed the meaning of your form.
they're semantically equivalent, it's just that sometimes it's nice to use one or the other.
Basically if the function is obvious enough you readily understand what %
, %2
and so on mean in the context by all means use #()
. Otherwise it's probably nicer to use fn
and name the arguments.
Oh, and you also can't nest #()
, so if you have to have a function within a function - use fn
.
For example compare this change I did in a PR to kioo when fixing something once - https://github.com/ckirkendall/kioo/commit/18838fe504c3e6770752f87503766081746c188d
So yeah, the rule of thumb is (reduce #(* % %2) some-collection)
is probably still fine, if the function is more complex - you probably want names.
if the semantic meaning is extremely obvious due to the context or shape of the function, however, using the anonymous reader function syntax (#()) may be a reasonable choice.
Yeah; most of the time I decide to use #()
first I then go back and turn it into fn
anyway.
(defn return-a-fn-that-multiples-by-5 [] #(* % 5)) ((return-a-fn-that-multiples-by-5) 5)
would return 25, and, arguably, using (fn [n] (* n 5))
is more noise than it needs to be.
that's a very extreme example though, so just use your best judgement. also, as always, it's good to be consistent.
@jaen: https://github.com/metosin/schema-tools/blob/master/src/schema_tools/core.cljc#L217
@juhoteperi: So this takes care of keys inside things like conditional
as opposed to a naive use of clojure.walk
, yes?
@jaen: No, optional-keys
is not recursive, it only works when given a map schema. There is however schema-tools.walk
you could walk over a Schema and then call optional-keys
for any maps.
@juhoteperi: I've tried this:
(def EventType
(s/enum :repair-requested))
(def RepairRequestedPayload
schemas/RepairRequest)
(def Event
(s/conditional
#(= (:type %) :repair-requested)
{:uuid UUID
:type EventType
:payload RepairRequestedPayload}))
(def EventQuery
(st-walk/walk Event st/optional-keys identity))
(s/validate EventQuery {:type :repair-requested :payload {:type :stability}})
and yet I get an error that rest of payload keys are missing. Am I doing something wrong?@jaen: Unline prewalk
ja postwalk
, walk
is not recursive itself but you would need to call the walk again inside the inner
@jaen: Something like this could work:
clj
(defn recursive-optional-keys [s]
(st-walk/walk s
(fn [x]
(let [y (recursive-optional-keys x)]
(if (plain-map? y)
(optional-keys y)
y)))
identity))
Also, could make sense to add prewalk
and postwalk
to schema-tools
Hey all, can anyone suggest a baby step to resolve StackOverflows from the attached code attempting to model the sieve of Eratosthenes... https://gist.github.com/paulspencerwilliams/9a5587d9826d1a6e5f94
@jaen: Perhaps you tried to call optional-keys
on non-map schema?
I think you want to test for (and (map? schema) (not (record? schema))
to distinguish Schema records from plain maps
I don't imagine there's an easy way to have a common part of a conditional schema and have only some keys differ?
The experimental abstract-map
Schema does allow something like that
Since you seem so knowledgeable about schema - do you think there's any way to do conditional coercion (that is a datum is coerced differently depending on the subschema it is in) with schema, or would I have to do it on top of that (by wrapping the values so I can differentiate them, or coercing separately)?
Hmm, the first option might be possible using dynamic binding, but I'm not sure
But that would only work in Clojure then, right? I guess I'll look into generating new schemas using the walker that would attach contextual information to relevant keys or something of the kind (because I don't think I'll be able to understand schema code well enough to modify it to let coercer get context information).
(s/defn test [a :- s/Int]
(+ 2 a))
=> #'boot.user/test
(test 2)
=> 4
(test "derp")
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
@ragge: thanks, wasn't aware of set-fn-validation!
, I've only used schema for input/output validation & coercion, never for functions.
sreenath.n: cheers, just reading code now
Anyone using chime to schedule jobs? I can't seem to figure out how to pass in job data other than use global state. Which won't work for me.
jstew may i recommend https://github.com/zcaudate/cronj
cronj is nice, and I already started using it. I need to add a range of random seconds to the start of each job which is what made me look at chime.
I can do the same with cronj, but have to start the job then sleep or timeout for a few random seconds but I don't want to do that if possible.