This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-15
Channels
- # aleph (14)
- # aws (5)
- # beginners (144)
- # bitcoin (1)
- # boot (14)
- # chestnut (13)
- # cljs-dev (58)
- # cljs-experience (1)
- # cljsrn (47)
- # clojure (107)
- # clojure-dev (9)
- # clojure-finland (12)
- # clojure-gamedev (4)
- # clojure-russia (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (5)
- # clojure-uk (28)
- # clojurescript (34)
- # cursive (9)
- # datomic (3)
- # emacs (11)
- # garden (16)
- # graphql (9)
- # hoplon (3)
- # jobs (2)
- # juxt (6)
- # off-topic (32)
- # om (10)
- # onyx (1)
- # pedestal (4)
- # proton (1)
- # re-frame (14)
- # reagent (8)
- # ring (1)
- # ring-swagger (34)
- # shadow-cljs (19)
- # sioux-falls (1)
- # spacemacs (16)
- # testing (14)
So I have the following macro in my code:
(defmacro run-sym [sym & args]
(require (symbol (namespace sym)))
`((resolve ~sym) ~@args))
Which I would think works, however when I run it I get the following error: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Named
. What causes this? And how can I fix it?sym needs to be a literal symbol, it can't be a form that returns one
you passed in (quote clojure.string/join)
that's a list
just leave off the '
most forms will automatically resolve symbols, macros don't
or you could use `(do ...) to put the require inside the macro body output too
then ~ on the symbol / namespace call etc.
come to think of it that's the only way to have one input that works with both forms I think...
@josh.freckleton hi, you can add any swagger data with key :swagger
, e.g. :swagger {:deprecated true}
.
Cursive also seems built around lein, and failed to find a load of my dependencies even after I'd converted my build.boot to a project.clj, so I gave up in favour of clojure-kit until Cursive gets proper boot support, then I'll try again
That might also have been because i have loads of different Clojure projects within a single 'project', but it didn't seem to work even when I just loaded one of them
yeah, i used to Cursive, but i have to use boot sometimes and then issues come. clojure-kit is something like cursive?
Did you try solutions like nightlight or atom for Clojure? I was trying atom in the past but it was definitely not ready then.
Well I use IntelliJ for a load of other languages I use, so I wanted something that I could do Clojure in there too
clojure-kit is an unofficial plugin for IntelliJ to do Clojure, but it is written by a guy who works for IntelliJ, so...
It's not as full featured as Cursive, but it doesn't have issues finding my dependencies, and gives me syntax highlighting which is the main thing I wanted
thx for sharing your experience with Intellij. I have similar situation, but as long as i have to use boot
i start to think again if intellij is good choice in such case
@kwladyka clojure-kit runs boot to figure out deps and to run a repl. I would prefer the other way around to integrate with IDEs. Ideal IDE would listen to proj configuration updates on a socket for maximum flexibility.
Useful if you want to default for nonexistent keys, rather than returning nil and then checking if you got a nil and returning some other value if you did
Hi guys, I'm hitting a really weird compilation error with defprotocol
- namely java.lang.RuntimeException: Method code too large!
It's a big protocol, but surely there isn't a limit to how many methods a protocol can have?
Anyone seen this before? (And can tell me how to overcome the underlying problem, without having to refactor... well... everything?)
Have seemingly managed to prove that the issue is the number of methods I'm defining (by commenting out chunks until the error went away; and then commenting out different chunks to make sure it wasn't related to the last chunk I redacted)
@carter.andrewj there's a limit to how much code you can put in a single method.
Are you using core.match or core.async's go?
Yeah, but this is just the protocol - the methods haven't even started compiling at this point
It's about 50 - haven't counted
in a single protocol?
I'm guessing that defining the protocol is defining a method with some inlined table somewhere or something
no, the're just a fair amount of code involved in defprotocol
Okay - I managed to solve it by cutting the definition in half and chaining the second half as an extend-protocol
But would rather not have to hack my way around it
But really, break that thing up a bit. Good protocols are normally < 10methods, most should be <5
It's a core protocol defining a lot of helpers for higher-order classes
why can't these just be normal functions?
And often you can break stuff down. Instead of IList for example you can have IAppendable, ICounted, IIndexable, etc.
Most of the time you can almost have a 1:1 ratio of protocols and methods.
Some have 2-3, others have up to 12
I'm doing is writing a library for handling analytical data contextually - so the higher-level types are things like a measure, aggregate or transform, etc... The goal is to be able to handle these things generically (hence the protocols) but they also have a hierarchical ownership (e.g. a transform might operate on two aggregates)
for instance, how general is your protocol? maybe carve out 7 protocols that are more specific
Yeah, it can certainly be broken down into sub-sections
and if you have up to 12, then you have at least 12 types and you have therefore 600 functions implementing this protocol!
Well each of those has their own protocol already for the methods specific to their types - this is the general set of methods that are universal, but require different implementations
for example, look at core.matrix: https://github.com/mikera/core.matrix/blob/develop/src/main/clojure/clojure/core/matrix/protocols.cljc#L173 A lot of things be done to a matrix, but they're all given their own protocol.
I can absolutely break it out into smaller sub-protocols, it just seemed tidier to keep everything in the same place - given that a lot of them are going to always be dependent on the others
life will be better if you break them up into areas of responsibility/change I guarantee it
Happy to follow that way of operation
And there are certainly clearly defined areas that I could break out
Is it going to be general code-management issues I run into without that? Or something else?
(Just trying to better inform myself)
so crazy thought. if you have 50 functions and up to 12 different implementations, many many of these must have common implementations. at this point i think i might write a macro to do this for me
(I did have things broken out in earlier iterations - but it seemed pointlessly opaque to have every type of dependent record invoking the same 10 different protocols
(Ha - I did consider that it might have been worth learning macros to do this, but that was only after I'd gone a significant distance)
the main thing is don't define the protocols and implementations in the same file, people almost always want to do this, but it very easily turns in to circular references between the implementations helper code and the protocol definitions
No worries there - I've got everything filed away separately already
Anyway - thanks for the help guys
Hi all, I’ve started on a project to address the read and start-up time in Clojure. It’s a bit of an experiment at the moment so far I have it doing most symbol extraction, next I’ll be working to build an AST. Lexing the Pedestal repo at the moment takes about 184ms which is spread across 4 readers and 16 lexers. If you’re interested in taking a peek it’s here: https://github.com/nfisher/cljbuck
@dpsutton You can often get a similar effect by returning `(do ,,,) with multiple forms inside the do.
i was wondering if he could get around the method too large boundary by returning a (deftype ~type [implement protocol]) (extend-protocol ~type [more stuff here])
but this is apparently not possible. a do
form would preserve and actually exacerbate the method too large error
yeah, calling out to functions is the best way of fixing that
now, you could make a macro that defined a function and also made a method body that called it…
not especially efficient but it could help maybe?
QUESTION: Any way I can take a arbitrary Java POJO and print it into something the Clojure reader can read back into the Java POJO?
all 4 files compile and pass tests on cider. two_test.clj
does not compile on lein though, with Exception in thread "main" java.io.FileNotFoundException:
error, regarding parent.child.one-test
My hunch is that even with the dependencies specified, only items in src/
can be imported into other namespaces.
there is no difference, if you are seeing one it is as a result of something you did
my guess would be you haven't restarted the cider repl in a while and the running code has diverged from what you have in your files