This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-23
Channels
- # admin-announcements (6)
- # aleph (3)
- # beginners (38)
- # boot (119)
- # braid-chat (15)
- # braveandtrue (1)
- # clara (4)
- # cljs-dev (56)
- # cljsfiddle (12)
- # cljsjs (15)
- # cljsrn (6)
- # clojars (4)
- # clojure (113)
- # clojure-art (1)
- # clojure-berlin (1)
- # clojure-dusseldorf (3)
- # clojure-india (15)
- # clojure-new-zealand (3)
- # clojure-poland (1)
- # clojure-russia (83)
- # clojure-uk (18)
- # clojurescript (97)
- # community-development (9)
- # cursive (1)
- # data-science (1)
- # datomic (12)
- # emacs (14)
- # hoplon (350)
- # immutant (2)
- # jobs (2)
- # jobs-discuss (23)
- # keechma (74)
- # liberator (1)
- # off-topic (1)
- # om (127)
- # onyx (54)
- # parinfer (74)
- # pedestal (1)
- # proton (5)
- # re-frame (6)
- # reagent (4)
- # remote-jobs (17)
- # ring-swagger (1)
- # slack-help (5)
- # untangled (16)
- # yada (21)
@danielsz: you are hitting https://github.com/clojars/clojars-web/issues/514 - I'll deploy the fix for that tonight
For developing a publically available REST API, what tools are most often used? I assume liberator is still favored.
@tcrawley no problem at all, thank you so much for the quick response. Big relief :-)
@jindrichm: That's what :hierarchy
option in multimethods is for. Also allows to add/remove "aliases" during runtime.
@rauh: That only works when the dispatch value can be derive
d, right? Moreover, you cannot extend third-party multimethod.
@jindrichm: 2x correct . You probably could mess with
get-method
and then dynamically add it.
any multimethod definition that can only return a fixed set of values is broken by design, IMHO -- not that this would help you, though
e.g. if the dispatch method would only ever return :a, 😛 or :c, regardless of the dispatch value
That's not the problem I want to solve. There's a third-party multimethod dispatching on strings, for which I want to reuse implementation for a specific dispatch value.
I thought I could do it by changing the implementation of the function to identity, but of course that would still catch the interface
Perhaps clearer: In an external namespace a protocol function is defined for clojure.lang.Associative, which will handle maps, vectors and map entries. However, I only want it to handle Maps (IPersistentMap ?)
this is really weird. I'm getting the same compiler error no matter what is in a file
CompilerException java.lang.IllegalArgumentException: Parameter declaration missing, compiling:([REDACTED].clj:12:1)
every time
never mind
I had a duplicate file with the same namespace in my test sources
weird
How can I archive this (nth (:children (nth (:children (nth menu-h 0)) 1)) 1)
with a clojure function, to process arbitrary depths?
Anyone here tried using GravityLabs Goose (https://github.com/GravityLabs/goose) with Clojure? There used to be some ports and/or wrappers, but they've all gone unmaintained. If not, got a Clojure alternative to Goose for content extraction?
@danielgrosse: what @rm said get-in
, or even with threading macro: (-> menu-h (nth 0) :children (nth 1) :children (nth 1))
. Or do you mean you want to somehow automate the construction of that "path"?
Question: I've been happily using transit-cljs for json+transit parsing, so I'm looking at transit-clj for JSON parsing on the backend. I've worked through the transit-clj readme and can now convert a JSON string to Clojure data, viz.:
(transit/read (transit/reader (ByteArrayInputStream. (.getBytes "{\"name\":\"Donald\",\"age\":19}")) :json))
I can certainly do this. But because it just seems more baroque than the ClojureScript version, I wanted to confirm that this is indeed how I ought to be parsing JSON with Transit in Clojure. Specifically, if I have a file containing thousands of lines, each containing valid JSON ("line-delimited JSON"), that I ought to be converting each line's string to a byte array, then a ByteArrayInputStream, then a transit reader, before invoking transit/read
@fasiha @rm Thanks for the advises. I want to build the command by a given vector [0 1 3] where each number is the position in the structure.
@danielgrosse: try this: (get-in MY-MAP (flatten (map #(vector % :children) [0 1 3])))
, replace MY-MAP
with your actual map, and [0 1 3]
with your path. To see how this works:
cljs.user=> (flatten (map #(vector % :children) [0 1 3]))
(0 :children 1 :children 3 :children)
(You could build that path vector many ways, e.g., instead of flatten
and map
, you could probably use into
)
@fasiha: thank you very much. This is genious
@fasiha: @danielgrosse (mapcat #(vector % :children) [0 1 3])
When I want to follow a path through a nested map, how can I gather information on each object into a new map?
@danielgrosse: You're probably going to end up using clojure.walk, or something like spectre (https://github.com/nathanmarz/specter).
I’m trying to implement a protocol that is in a different ns using extend
, but it isn’t working for me. I might be missing something obvious. E.g:
(ns prots.blues
(:require [prots.protocols :as p]))
(deftype BluesPlayer [fname lname]
p/Speaks
(speak [this] "HOO"))
(extend BluesPlayer
p/Rocks
{:rocks (fn [this] "HOOOO")})
(def wolf (BluesPlayer. "Wolfy" "Howls"))
I can do (.speaks wolf)
, but (.rocks wolf)
throws an exception
if I implement p/Rocks when I declare the
BluesPlayer` type, then it works.
I’m on clojure 1.8rauh++
@roberto Look at the curly braces around :rocks, plus you made :rocks a keyword instead of the function name symbol
I thought it was supposed to be a map https://clojuredocs.org/clojure.core/extend
I find it easier to use extend-type when extending in another namespace (extend-type BluesPlayer p/Rocks (rocks [_] "HOOOO"))
was just trying to get something working and figure out what was the issue, so I went one layer lower
Nah, just been extending protocols in another namespace for half a day and it works quite alright
So what I did was require the namespace the protocol is in under an alias, and referred the protocol function name
oh, do you have to do anything special to the files with the protocols? Like maybe do a :gen-class
?
Then my extend-type was something like this: (extend-type ArrayType jmx/Destract (objects->data [cd] (bean cd)))
Refer seems not to be necessary, this works as well (extend-type ArrayType jmx/Destract (jmx/objects->data [cd] (bean cd)))
Usually it's one protocol, like IMakeMusic
, with speak
and rock
as functions inside that protocol
yeah, i was trying to see if this works http://davedellacosta.com/cljs-protocols
that works fine for me, it just doesn’t work when I extract protocols into their own files. I’ll take a break from this for now. It was just an academic exercise I was trying.
I think Clojure can sometimes be faster than Scala at run time because Clojure needs to allocate less anonymous functions. Am I correct? Example:
https://gist.github.com/borkdude/2772ccead843832c0956
Every time you update the map inside the atom
you need to allocate an anonymous function. In clojure you can just pass assoc
+ args, no overhead.
How can I run tests on https://github.com/dakrone/lein-bikeshed if lein test
doesn’t work?
my usecase is that I have some dynamic variables that I want to set to be equal to the value of some keys in an .edn
file and I don't want to repeat myself too much
@urbanslug: I think it's just to serve as an example of "bad formatted files, with trailing newlines". Running lein bikeshed
on the project shows (among other stuff):
[...]
Checking for files ending in blank lines.
Badly formatted files:
/home/nicolas/projects/lein-bikeshed/test/bikeshed/core_test.clj
/home/nicolas/projects/lein-bikeshed/test/bikeshed/core_test.cljs
[...]
about to write my first midje tests, for a channel. This is where all hell breaks loose in Scala (testing async code). I'm hoping for the best here... any advice?
@fommil that's right about binding
. You can see the relevant code here: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L1849
My advice re: midje + core.async is just to <!!
the channel and check the value on it. What you don't want to do is assert inside the async thread
@isaac_cambron: cool thanks, I started doing that it's good to get the approach confirmed. Can clojure run tests in parallel? I can see this slowing things down if I'm blocking everywhere.
There System/nanoTime
I've never run tests in parallel, though I'm sure there's a way
heh, I was about to ask some questions about midje, then I realised they have 80 pages on their wiki
is there a better notation than this for a midje assertion? (just {:result :ping :time (partial <= 50.0)})
. The partial is a bit ugly
is there a way to define a destructuring in a single place? for example, when working with sente i find that i’m doing this all over the place
(let [{[ev-id ev-data] :event :as message} (<! chsk-recv)]
…)
doing something like this feels weird
(defn -ev-id
[{[ev-id] :event}]
ev-id)
(defn -ev-data
[{[_ ev-data] :event}]
ev-data)
@akjetma: maybe you could define a kind of middleware that transforms your arguments into a more convenient format