This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-03
Channels
- # aleph (1)
- # beginners (99)
- # boot (16)
- # cider (35)
- # cljs-dev (46)
- # cljsrn (7)
- # clojure (152)
- # clojure-austin (7)
- # clojure-dusseldorf (8)
- # clojure-italy (1)
- # clojure-uk (7)
- # clojurescript (3)
- # core-async (12)
- # css (8)
- # cursive (18)
- # datascript (2)
- # datomic (19)
- # defnpodcast (6)
- # duct (3)
- # editors (8)
- # emacs (8)
- # figwheel (1)
- # fulcro (20)
- # hoplon (18)
- # jobs-discuss (5)
- # lein-figwheel (1)
- # luminus (3)
- # lumo (19)
- # off-topic (15)
- # onyx (9)
- # parinfer (2)
- # planck (6)
- # portland-or (7)
- # re-frame (4)
- # reagent (7)
- # remote-jobs (1)
- # ring (6)
- # ring-swagger (4)
- # spacemacs (10)
- # specter (3)
- # unrepl (131)
I’m trying to do something similar from intelliJ, gorilla forces you to type in the browser..
Not sure this is sensible/useful in any way, but I was wondering if there’s a particularly good way of modifying a single element of an infinite sequence. You can’t just assoc with an index. I came up with:
(defn assoc-nth [s n v]
(let [[l r] (split-at n s)]
(concat l (vector v) (rest r))))
(take 10 (assoc-nth (repeat 0) 3 7))
(0 0 0 7 0 0 0 0 0 0)
.. but was wondering if there’s a better way. Googling yielded nothing.I would just store the "modifications" in a map. Then take values from the map at that index if it exists, otherwise take from the stream.
`(let [m {3 7}] (->> (repeat 0) (map-indexed #(m %1 %2)) (take 10)))`
(let [m {3 7}]
(->> (repeat 0)
(map-indexed #(m %1 %2))
(take 10)))
@scallions No need for the anonymous function
So without the anon.
(let [m {3 7 5 9}]
(->> (repeat 0)
(map-indexed m)
(take 10)))
(0 0 0 7 0 9 0 0 0 0)
Yea works the same! I should of seen it coming with those args in sequential order.
Hi, what would you use to make a gui? Fn-fx seemed interesting but also now abandoned, with issues on github going unanswered. Also cljs+electron is not looking much used. As a beginner with clojure I was looking for something straightforward and with many resources. But there doesn't seem to be anything.
@teikfaiv what do you need? you could use hiccup to send html as response, you might not needs cljs?
Maybe you could start with a luminus with re-frame, it give you both a back and front-and and some usefull tools like re-frame out of the box? It’s kind of how I started getting into clojure.
there is https://github.com/daveray/seesaw, I’ve made some toy projects with it and I had a pretty good experience, can’t comment on it for serious production use though
Also http://nils-blum-oeste.net/functional-gui-programming-with-clojure-and-javafx-meet-halgarifn-fx/
Quick compojure-api question: I want to send a date to the server, and have my spec based route coerce it to a java.util.Date, using spec/inst?
. I send application/transit+json, and encode the param like this; http://some-url?myParam=Wed Dec 27 2017 11:48:05 GMT+0100 (CET)
What is the recommended way of doing this, because I get a spec validation error on my route. I basically just send a javascript Date directly to the server. What format should I send it in such that it is automatically coerced to a java.util.Date?
cc @ikitommi
[immutant.web.internal.undertow$create_http_handler$reify__17886 handleRequest undertow.clj 239] [org.projectodd.wunderboss.web.undertow.async.websocket.UndertowWebsocket$2 handleRequest UndertowWebsocket.java 109] does immutant/undertow upgrade to websockets by default?
What would be the easiest IDE setup for clojure on linux ? For someone coming from sublime text / vs code
VS Code is available also for Linux, I think. But if you want “full” IDE, I’d look into IntelliJ IDEA with Cursive plugin: https://cursive-ide.com/
@kah0ona 2018-01-03T13:05:11.581Z
should work, see https://github.com/metosin/schema-tools/blob/master/test/cljc/schema_tools/coerce_test.cljc#L171-L193
oh, spec so: https://github.com/metosin/spec-tools/blob/master/test/cljc/spec_tools/conform_test.cljc#L33-L36
Is there any way to enforce certain options must be passed explicitly in clojure.tools.cli
? As far as I can tell, this is no longer possible: https://github.com/clojure/tools.cli/commit/47984bc7413d7a675ea9586d08d461d4a016060e
my naive first approach was to do
clojure
(defmacro make-proxy [proto-impl]
(let [forms (make-forms proto-impl)]
`(proxy [MyClass] [] ~@forms)))
This doesn't work since proto-impl
is a form and not the protocol implementation at compile time.
Would there be a variant to this approach that would allow me to build forms only once and thus have a proxy which does not need to rely on satisfies?
?
(defn make-forms [x]
(cond-> []
(satisfies? Foo x) (conj '(getFoo [] (get-foo x)))
(satisfies? Bar x) (conj '(getBar [] (get-bar x)))))
(defmacro make-proxy [proto-impl]
`(let [forms# (make-forms ~proto-impl)]
(concat '(proxy [MyClass] []) forms#)))
I seem to lose all hinting capacity along the way though, which is a big loss for facades.
why would (clojure.data.json/read-str (slurp filename))
throw java.lang.StringBuilder cannot be cast to java.io.PushbackReader,
?
If anyone is interested, I reverted to a non-macro based approach, which remains fast but is somewhat inelegant: https://github.com/pyr/net/commit/a489eb71f5ff4ab474ff0408d898581a67902b62
You can't make a negative vote but can try to explain (in the ticket or here) why you dislike it and how you'd approach this
This has actually been a dilemma of mine: Protocols are nice that they are open to extension later However, all older impl’s do not support newly added functions and you have no way to check that - so you still are broken
@ghadi right, I get your point but there are times when you actually need satisfies?
and it often happens to be in hot paths
I don’t see where satisfies?
really helps with anything since it doesn’t tell you about unsupported operations anyways
It encourages a bit of an abuse of polymorphism, making tests for specific classes of things rather than implementing and calling the polymorphic method
i.e. tools reader needs it to know whehter it can annotate output with line/col info or not -- I had to work around it by hardcoding instance checks
there's the workaround of extending protocols to Object for the catch-all case rather than testing with satisfies? and using the else branch
I just struggle to see how you can grow a protocol at all since it seems to just break everything that exists - or at least make them all incompatible
Yes, so if they are not really open to extension later, I wish you couldn’t have partial impl’s
and you impl P2
on Object for all those that don’t support it because they are old and use P
@mikerod at the moment it's the only tool I have, bar ugly workarounds like the one I used above
(defprotocol P2 (old-f-from-p [this]) (new-f [this]))
(extend-type Object
P2
(old-f-from-p [this] ::no-impl)
(new-f [this] ::no-impl))
(defn using p-or-p2 [o]
(let [v (new-f o)]
(if (= ::no-impl v) (compat-layer (old-f o)) v)))
I mean, I don’t even try on Object
for some cases like this, just make them a faster “satisfies” check that can actually check at the fn level. hah
However, I see really no good reason to not fully implement a protocol. I think you are supposed to anyways from some docs (have to check). Perhaps it isn’t checked just for pragmatic reasons etc
i don't understand what you're point is, satisfies has nothng to do with partial protocol implementations
Focusing purely on the satisfies part of my comments here (since I guess no one wants to talk about extending protocols right now, hah)
(defprotocol P
(foo [this]))
(extend-type Object
P
(foo [this] ::no-impl))
(defn maybe-use-p-on-x [x]
(let [v (foo x)]
(if (= v ::no-impl)
(do-not-do-stuff x)
(do-stuff v))))
Something like that can be used in place of satsifies?
right? Also, I’d think that is fast.I have used satisfies?
in
(defprotocol SomeOps
(-foo [this x] "Establish the fooness of x for this"))
(s/def :some-ops/subject #(satisfies? SomeOps %))
(s/def :some-ops/x any?)
(s/fdef foo
:args (s/cat :this :some-ops/subject
:x :some-ops/x)
:ret boolean?)
(defn foo
"Establish the fooness of x for this (wrapper for `-foo`)"
[this x]
(-foo this x))
in order to make sure I got the right sort of thing inboundI'm having interop issues with https://docs.oracle.com/javase/8/docs/api/javax/tools/SimpleJavaFileObject.html#SimpleJavaFileObject-java.net.URI-javax.tools.JavaFileObject.Kind-
user=> (javax.tools.SimpleJavaFileObject. (.toURI (io/resource "ClojureMainBootstrapJarClassLoader.java")) javax.tools.JavaFileObject$Kind/SOURCE)
CompilerException java.lang.IllegalArgumentException: No matching ctor found for class javax.tools.SimpleJavaFileObject, compiling:(NO_SOURCE_PATH:36:1)
I don't understand how I am getting this wrong.Is there a clojure equivalent to:
class MyFileObject extends SimpleJavaFileObject {
MyFileObject() {
super(URI.create("myfo:///Test.java"), SOURCE);
}
}
It can be anonymous, I can't understand how to do it with proxy
though.@dominicm (proxy [javax.tools.SimpleJavaFileObject] [(java.net.URI/create "") javax.tools.JavaFileObject$Kind/SOURCE])
for an instance
you might need to explicitly call class
on that thing to return the class created though right?
also @bronsa there’s a question in #beginners about gen-class you might be able to help with - I thought I understood the issue and it appears it’s beyond me
I have no idea what this clojure.core.match code does:
(match [v t-p]
[(true :<< nil?) tp] (g tp)
[(true :<< i?) :r] v
[(false :<< i?) :r] (g :r)
[(false :<< i?) _] v
[(true :<< i?) tp] (g tp)
:else(...)
(variable names redacted)probably there in this form just for stylistic purposes, to match the shape of the other patterns
what that syntax means is, apply the function to the right of :<<
to the argument at that position, and match the return type against the value to the left
does this mechanism correspond to something described in https://github.com/clojure/core.match/wiki/Overview ?
Functions can’t call macros. They can return lists which could be macroexpanded, or they can be implemented using macros which are fully expanded within their definition.
@mping you can quote the function form and macroexpand the whole thing
@noisesmith didn’t work
=> (clojure.walk/macroexpand-all '(defn foo [x] (or x 1)))
(def foo (fn* ([x] (let* [or__5238__auto__ x] (if or__5238__auto__ or__5238__auto__ 1)))))
I should have mentioned clojure.walk/macroexpand-all (forgot that it would be needed for this)
oh, weird
ahh, that makes sense
you can macroexpand (foo 3) but you wont’ get anything useful - because foo isn’t a macro
macros are functions that take forms and return new forms, expansion makes sense in that context
expansion can’t do anything useful with something that doesn’t operate on forms