This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-08
Channels
- # bangalore-clj (5)
- # beginners (6)
- # boot (66)
- # cider (48)
- # cljsrn (14)
- # clojure (699)
- # clojure-austin (2)
- # clojure-berlin (1)
- # clojure-boston (5)
- # clojure-dev (3)
- # clojure-india (7)
- # clojure-italy (24)
- # clojure-nl (5)
- # clojure-russia (33)
- # clojure-spec (30)
- # clojure-uk (64)
- # clojure-ukraine (22)
- # clojurescript (123)
- # clojurewest (1)
- # cursive (18)
- # datascript (44)
- # datomic (12)
- # dirac (46)
- # figwheel (1)
- # gsoc (5)
- # hoplon (6)
- # immutant (29)
- # instaparse (1)
- # juxt (26)
- # lein-figwheel (5)
- # leiningen (4)
- # luminus (8)
- # mount (56)
- # off-topic (60)
- # om (67)
- # om-next (1)
- # onyx (8)
- # proton (28)
- # re-frame (125)
- # ring (3)
- # ring-swagger (3)
- # specter (22)
- # testing (2)
- # unrepl (1)
- # untangled (91)
instead of writing
(defn my-add [x y]
...)
is it possible to somehow attach extra info to it?
(defn my-add [^:int x ^:int y]
...)
Is there a more elegant way to implement java.util.Map
in use case such as:
(deftype GenericAvroMap [^Schema s ^java.util.Map m]
GenericContainer
(getSchema [_] s)
java.util.Map
(clear [_]
(.clear m))
(compute [_ k remapping-fn]
(.compute m k remapping-fn))
(computeIfAbsent [_ k mapping-fn]
(.computeIfAbsent m k mapping-fn))
(computeIfPresent [_ k remapping-fn]
(.computeIfPresent m k remapping-fn))
(containsKey [_ k]
(.containsKey m k))
(containsValue [_ v]
(.containsValue m v))
(entrySet [_]
(.entrySet m))
(equals [_ other]
(.equals m other))
(forEach [_ action]
(.forEach m action))
(get [_ k]
(.get m k))
(getOrDefault [_ k default]
(.getOrDefault m k default))
(hashCode [_]
(.hashCode m))
(isEmpty [_]
(.isEmpty m))
(keySet [_]
(.keySet m))
(merge [_ k v remapping-fn]
(.merge m k v remapping-fn))
(put [_ k v]
(.put m k v))
(putAll [_ m2]
(.putAll m m2))
(putIfAbsent [_ k v]
(.putIfAbsent m k v))
(remove [_ k]
(.remove m k))
(remove [_ k v]
(.remove m k v))
(replace [_ k v]
(.replace m k v))
(replace [_ k v new-value]
(.replace m k v new-value))
(replaceAll [_ f]
(.replaceAll m f))
(size [_]
(.size m))
(values [_]
(.values m)))
Without using a library such as potemkin
: https://github.com/ztellman/potemkin
what's wrong with that code ^^
Proxy does something like that, but I'd be tempted to just use the code you have here
how does a fully qualified class name work in clojure, if say, i'm depending on a java library from maven central like org.jogamp.joal/joal
supposing I wanted a specific class, what would its fully qualified class name look like in clojure?
@bcbradley it would look just like in the documentation, for example, the first class in that list: com.jogamp.opengl.math.geom.AABBox
Hi fam. What's the best server for doing server-side events @ 200k connections/server? (sparse traffic per connection). httpkit?
@bradford http-kit is very straightforward, and my testing has shown it to be quite good when compared to other clojure http servers. You may want to give this a read, as depending on your hardware, you may need to tweak some settings to increase the max file descriptors and ports http://www.http-kit.org/600k-concurrent-connection-http-kit.html
@joshjones Thank you! Do you know if the example at https://groups.google.com/forum/#!topic/clojure/DbBzM3AG9wM is the 'current' way of implementing SSE, or is there a more up-to-date example?
I'd also look at Pedestal, may take a bit of testing, but there's no reason why it couldn't handle that many connections. And the Pedestal SSE implementation is pretty mature.
My biggest complaint with http-kit is that it's 100% custom code (last I checked). I prefer to use systems based on better established base libraries.
but that's just my opinion
The biggest issues you'll encounter with any solution however is memory usage (can't have a thread per request), and configuring the OS. So it seems more of a configuration problem than anything else.
Whatever option you go with, I don't think there's a out-of-the-box solution that will give you 200k connections, as that use case is pretty rare.
I think most modern libraries like http-kit do something besides one-OS-thread-per-connection, I'm not quite sure the internals. I know some very high concurrency httpkit deployments, though.
@yedi, call (macroexpand '(->> form #(conj % base-rect)))
and compare the results
and then (macroexpand '(-> form (conj base-rect)))
and see what you get
@bradford I like http-kit
for a straight forward API, but it does have a bottleneck: a single thread to handle incoming requests: https://github.com/http-kit/http-kit/blob/e1c18408fc518730f574075638590c0ecf64c6bc/src/java/org/httpkit/server/HttpServer.java#L269-L315 here are some benchmarks with it vs. other servers: https://github.com/ptaoussanis/clojure-web-server-benchmarks/tree/master/results/60k-keepalive#60k-keepalive
@bradford I would give immutant
and aleph
a try as well if you have time to experiment
@tbaldridge @seancorfield so i did that, and im still not really sure i understand why it works that way
like in this case (macroexpand '(-> form (conj base-rect))
, why does conj
properly get placed in front of the argument we want (when it generates the fn call)
but if you were to use an anon function it doesn't just place the entire anon fn in front of that argument and call it
@yedi #(conj % base-rect)
is short for (fn [x] (conj x base-rect))
so when you ->>
into that, you get (fn [x] (conj x base-rect) threaded-var-goes-here)
As @joshjones says, you need to wrap the (anon) function in paren to get the result you want
(->> form (#(conj % base-rect)))
=> (->> form ( (fn [x] (conj x base-rect)) ))
=> ( (fn [x] (conj x base-rect)) form )
(but in this case you’re better off just doing (-> form (conj base-rect))
)
ah, i wonder why the macro doesn't take the surrounding parens in the fn definition into account when generating the expanded form
Er, it does.
(->> form (fn [x] (conj x base-rect)))
=> (fn [x] (conj x base-rect) form)
— that’s exactly how threading is defined.
Consider that (macroexpand '(->> 1 (2 3 4)))
=> (2 3 4 1)
— pure symbolic substitution, not necessarily a valid expression you can evaluate.
Yes, the special case is if the form has no ( )
they are added.
so (->> x inc)
is first transformed to (->> x (inc))
and then to (inc x)
boot.user=> (macroexpand '(->> thing (some [arg] (an arg expr))))
(some [arg] (an arg expr) thing)
Macros “don’t care” what the symbols are — they don’t get any meaning until after macro expansion (in general).
ns
is a macro so it interprets raw s-expressions...
You'll want to call create-ns
and stuff like that.
You don't need to call ns
at all. It just expands to calls to other functions -- you should call those directly.
(in-ns 'foo.bar.quux)
is valid and creates the namespace and sets *ns*
to that -- which is basically what ns
does under the hood...
then the documentation for symbol should be updated to say that valid tokens are alphanumeric characters and *, +, !, -, _, ? and .
Do (macroexpand '(ns clojogl.graph.curve))
to see what it does behind the scenes
It starts by calling in-ns
What you can create as a symbol is different to what you can programmatically produce as a symbol. Same for keywords.
For example (keyword "Hi Brian!")
-- but you cannot type :Hi Brian!
and (symbol "! @ # $ % ^ & * ( )")
will produce a Symbol -- but you can't type it in literally.
(symbol ".")
is valid 🙂
i'm hoping to make a wrapper around jogl so we can do some low level graphics stuff with clojure
FWIW (def a.b 42)
does work (and defines a symbol with a dot in its name)
Well, just because it's accepted doesn't mean it's "defined" per the docs.
You can't do (let [x.y 13] ...)
for example.
So now I went and read the docs:
'.' has special meaning - it can be used one or more times in the middle of a symbol to designate a fully-qualified class name, e.g. java.util.BitSet, or in namespace names. Symbols beginning or ending with '.' are reserved by Clojure. Symbols containing / or . are said to be 'qualified'.
So it explicitly says .
is allowed and has a particular meaning.
sorry i was getting it from here https://clojuredocs.org/clojure.core/symbol
(I only tend to consult the docs when something doesn't work 🙂 )
http://clojuredocs.org is not an official site
Both http://clojuredocs.org and http://clojure-doc.org are community-maintained. http://clojure.org is the "official word".
Re: Java methods... I'd probably use Java's reflection stuff but I'd have to go read the docs... I try not to keep too much of the Java API Docs in my head 😐
Or maybe the Clojure reflection package if you wanted data structures... again, I'd have to go read those docs...
my "structures" look something like this:
{"graph.curve"
{"OutlineShape"
{"addEmptyOutline"
{:doc "Add a new empty Outline to the end of this shape's outline list. If get-last-outline is empty already, no new one will be added. After a call to this functiona ll new vertices added will belong to the new outline. "
:args ["outline-shape"]
:pure false}}}}
I don't know about Java, but you can get all Clojure namespaces as a sequence with all-ns
.
I don't know that you can start from a package name and find all classes that belong to it...? I think you're right that you need to load a class to be able to reflect on it.
@tech_hutch That will only return the loaded namespaces I believe.
here is what i'm looking at right now http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/
I guess you could read the JAR itself to get a list of all the .class
files?
@seancorfield ohh. Is there any way to get the subnamespaces of a namespace in Clojure?
i just don't know if i can actually do reflection at this level because it don't know what is loaded when clojure begins evaluating
@tech_hutch If you start a REPL in a project and immediately run (all-ns)
it will only show the already-loaded namespaces -- it won't show any of the project's namespaces until they have been require
d.
For example, I just created a new project -- boot -d boot/new new -t app -n hutch; cd hutch; boot repl
-- and (all-ns)
doesn't show the hutch.core
ns even tho' hutch/core.clj
is on the classpath and can be loaded.
So, no, short of walking the class path and the filesystem, you can't find "all" namespaces (to include the not-yet-loaded ones).
Oh, okay.
so you are saying i'd be better off generating the clojure code and making a library out of that, rather than asking clojure to generate the library at load time?
@bcbradley I think that generating Clojure source from the Java classes in the JAR file is probably going to be an easier problem to solve -- and would let you tweak the generated code as well.
The docstring for all-ns
just says "Returns a sequence of all namespaces." It could probably be more descriptive, then.
Trying to generate Clojure stubs on the fly from an arbitrary Java library... sounds like an interesting problem to solve but I'm not sure how tractable (or performant) it would be...
@tech_hutch I agree. And the source
doesn't give you any more clues either.
i'm sure there is a clojure function somewhere that gives me the string representation of the functions in a namespace
If you load a namespace, you can get a list of symbols in it and call clojure.repl/source
on those I guess...?
There's ns-map
.
As for loading the jogl library classes, you'd need to do something to explicitly reference them, in order to get them loaded (as I understand things).
If you don't reference classes, they don't get loaded.
Reference.
Do you know of any online repls that have the latest version of Clojure? http://tryclj.com runs 1.4.
Class.forName( someClassName )
will give you a Class object for the named class, if it can be loaded.
(Class/forName some-class-name)
in Clojure 🙂
or "can be loaded if its on the classpath, and if it isn't loaded yet i'll load it and make you wait"
Thanks @jjttjj.
If it isn't on the classpath, you'll get an exception. Otherwise you'll get an instance of Class
describing the class -- after loading it if it wasn't already loaded.
I've been working on the JVM since 1997...
I'm just old 🙂
and there isn't really a good low level interface to opengl except penumbra, and that isn't actively maintained
I started doing commercial software development back in the early 80's... C and assembler, COBOL, moved to C++ in '92, picked up Java in '97...
I was on the X3J16 Standards Committee for eight years ('92-99) and secretary of it for the last three... I guess I'm proud of what we achieved... and it's been interesting to watch it grow since I left the committee... I still chat with several of the active members.
in fact its probably the most efficient language from that point of view that I know of
I learned Java in college, but haven't had much use for it since then.
The design goal was that you only pay for the features you use -- you should never pay a cost for features you do not use.
That drove a lot of what we did on J16.
Yes, it has gnarly syntax.
i guess the other thing i don't really like about it is that it tries to be everyone's friend
It was designed as a multi-paradigm language from the get-go.
Have you read The Design and Evolution of C++?
It's a good read -- fairly accessible and not very long -- explains a lot about why C++ is the way it is.
Reminds me of JavaScript. Everything and the kitchen sink.
without giving that paradigm ample time to prove or disprove itself in the wild before deciding whether to include it
it makes the language hard to understand for newcomers because documentation could be obsolete in 5 years
when you have these two competing interests in a language it causes the idiomatic time frame to shrink
something in c that was written 20 years ago that was idiomatic then is idiomatic now
Well, ISO and ANSI require that standards are reviewed and that updates are at least considered every five years as I recall...
what actually happens is different c++ programmers end up with a different understanding of what is idiomatic
and there is little community consensus on it because of the momentum of the language
and they have trouble reading eachother's code moreso than they would in another language
some of that trouble is naturally intrinsic to their different styles of programming
but a large chunk of it is exacerbated by c++ culture, which is derived from the shrinking idiomatic window i described.
You could levy the same complaint against Scala 🙂
I enjoyed writing C++ for 10-15 years. I adopted Java because, back then, it was a much cleaner, simpler, smaller language (and library).
Well i'm sure it was enjoyable, or you wouldn't have done it for 10-15 years (i hope)
Java's library quickly grew out of control and, since Java 5, the language itself has sprouted all sorts of ugly stuff. I parted ways with Java round about Java 5. The functional stuff in Java 8 would probably tempt me back if I was really still in the market for Java work...
that probably isn't fair, but thats the reality of it as far as i'm concerned, and C++ is a great technical asset but a poor language
For instance, I don't really like object oriented programming and Java is only second to smalltalk in that regard, but it has terrific documentation because it is so widely used
I would say that "C++ is a testament to what the ISO/ANSI process can achieve" and that's both a compliment and a criticism 😈
Java is a horrible OO language really 😐
Heh, yeah, Clojure is one of the best languages I've ever used for production work 🙂
He means Clojure.
i don't have any proof but i feel like when there are too many people working on providing assets and libraries for the same language, they end up trying to specialize away from eachother to not have duplication
and then you end up with a plethora of barely different libraries, so people try to differentiate further by combining pieces to make frameworks
I'm curious, what do you think of Clojure's "web framework" story? (or lack thereof)
Honestly i think there needs to be less focus on providing a framework for doing x or y, and more on exposing the protocols being used in a data oriented way
the benefit of doing that is that it informs the community about how to work with low level sockets in clojure
Clojure is designed as hosted language -- it is designed to piggyback on the JVM (and leverage its libraries).
thats fine, but most of the people i've met who have worked in clojure aren't jvm experts
or you can make low level internet protocol functions, get a lower cost X, and higher value Y to the community
Ring is a great abstraction for HTTP. I don't see any value in dealing with lower level stuff in this day and age.
Back in the day I wrote my fair share of SNA-level applications. It's a waste of everyone's time to have to recreate all that again.
i'm thinking of edn over a low level socket that isn't as basic as udp but isn't really tcp either
this is the kind of stuff i meant when i said it would produce value to the community
thats because people don't have the tools to ask these questions or inspect their assumptions
I suspect you'll have a hard time convincing anyone in the Clojure community to care about that low-level stuff when Clojure is all about abstractions and higher-level work.
I haven't been interested in that low level stuff for decades, since the world standardized on higher level abstractions 🙂
if it existed and it was as easy to use but gave you more power, speed, or whatever
I can't see what that would get you though, esp considering how large TCP packets can be these days
idk you'd have to take a deep look into the IP layer to figure out how and why tcp packets are so large
Okay, so let's say we're sending tuples of [int, int, string] (as Datomic does), app-level compression is going to give you way more bang for the buck then trying to say that you can re order some tuples
but the people who use it generally don't understand the interop that well, or know the jvm like the back of their hand
I'm glad there are people who care about that low-level stuff so I don't have to. I care some about HTTP as long as I have an abstraction for it. I care very little for WebSockets but I'll use an appropriate abstraction for it. Same with JDBC. I don't want to have to deal with the protocol under the hood. Even Java-level JDBC is painful. I like using clojure.java.jdbc
so I don't have to care about that stuff.
I think you assume too much to think that the Clojure community lacks people who understand the low-level inner workings of networking
if they do that understanding isn't well represented or exposed to the rest of the community in libraries, and there is an obvious reason for that
Dealing with the low-level stuff is very much a minority concern tho'.
and I still don't get what all that buys you. I have co-workers who have saturated 1gig connections via Clojure applications.
If you want high performance you don't have to write your own protocol, you just need a few tweaks here and there.
i'm talking about culture, what people think and how they think, and how the community organizes to solve problems
So here's the problem...you aren't really saying anything, besides "I think clojure people don't understand how to do low level stuff...it's a feeling I have"
in order to better organize people, you want idiomatic solutions to various problems exposed to eachother in the clojure language
I agree with some stuff, Ring is not the end-all-be-all. It's never been a great solution. That's why we have alternatives.
people do best when they can see eachother, and can see what they are working on clearly
if all the people who are best at solving problems of a specific domain X, say networking, don't share their knowledge with others
when you have a hosted language, if these smart people leverage the host language rather than exposing their knowledge to others in a library
Clojure is a very diverse community. But as with (nearly) all language communities, the vast majority of them are working on high-level applications and not low-level wiring stuff. That's true in every technology.
that's completely false, just because something is hosted doesn't mean you "can't" get lower.
I can do manual memory management in the JVM if I want...there's just never much use for it, except when there is, in which case I reach for a library that helps with that
But I'd love to hear a concrete example, thus far this discussion is way to abstract
Then you won't convince anyone -- and I think you have an extremely narrow view on this.
I think you over-estimate the importance of this issue to tech communities at large...?
Yes, it's not good enough to say "there's a problem that I can't describe because it's too abstract". You have to say "X is a perfect example of how the community is harmed by the situation I'm describing"
@bcbradley Can you provide an example of a tech community where you think there is this different priority?
from my point of view i have described it as best i can, and either the topic is to abstract to communicate briefly in english or I have made an assumption somewhere about our common understanding that isn't actually common, and that is causing a misunderstanding or lack of comprehension
@bcbradley I'll ask again: can you provide an example of a tech community where think there is this different priority?
and if there is anything whatsoever that would inhibit people's ability to sense eachother, then twenty eyes drops down to two eyes
@seancorfield no, i don't have an example i have principle
Well, remember that technology is a tool that people use for solving production problems. It's not some abstract ideal thought experiment.
Silo'd programmers are a real thing, but in general you'll find Clojure programmers to be very open-minded. For that matter core.async was created after we saw what some other languages were doing and said "heh, we can do that too".
then the argument i made about exposing people as much as possible to eachother's expertise should be reasonable
Right, but what I'm saying is we do that, if you have evidence to the contrary I'd love to hear it.
its not that it isn't possible for a person who is versed in networking to expose his expertise to others in the community in the clojure language, its just that he has little incentive to do it because he doesn't need to create the library for his own purposes
Right, and if he doesn't, what's the harm?
it makes the community that much better because the people in it are able to learn from him
The cold hard truth is...at the rate programmers are paid in relation to the cost of hardware, it's simpler/cheaper/etc. to spin up a new sever than to save 1% in processing power by optimizing some sort of network protocol.
You need to give a concrete example that is compelling. Otherwise it's just words and your vague feeling that something is wrong.
whether they have meaning or not to you is dependent on how hard you think about it
No that example is fine, it applies to many things. I could learn from a DB admin how to split tables across spindles, but 99% of the time it doesn't matter, and isn't worth the time/cost
You're hiding behind a claim that the Clojure community don't think -- and that seems a rather insulting position to take without any concrete evidence. Do you understand how high-handed you sound? (that's a genuine question -- I'm curious if you realize how you are coming across here)
But we are thinking. And the community do think. And that's what is so insulting about your position, I'm afraid.
"I'm only asking you to think"...
Then perhaps we think differently, or have different assumptions so to reach different conclusions
With my Clojurians Admin hat on, I'm tempted to ask you to take a time out from the community and think yourself about this sort of engagement...
You haven't "offended" me -- you're just taking a very insulting position to the community as a whole, without providing justification for it.
if you see it as insulting and I don't, what could cause us to have such different viewpoints?
I'm not an expert in clojure or java, and I have far less experience than most of the people in this channel
Clojure programmers think more than any programmer group I've ever been a member of. Infact one of the original talks Rich gave was on the very subject of thinking. Hammock Time was coined by this community, so if you are saying the community doesn't think and can't give a good example or argument to support your opinion, I have to assume you are either uninformed about the community or trolling.
It's fine to say that we don't think...and I'll listen...as long as you can give me an example or argue a point on that subject. Otherwise it's just a waste of everyone's time.
Great, have an example?
It's not offensive per se, it's just if you want to argue a point, bring some facts, or some common ground we can meet on.
And it's very rare that two people will solve the same problem, often there are tradeoffs. There is no such thing as "the best solution" in programming, everything is a tradeoff, everything is a compromise. So often these duplicated projects are just a different sent of tradeoffs valued over other sets of tradeoffs.
As an anecdote after reading through the conversation above, I have seen a much greater focus on low level performance (for a purpose) and interest in the implementation details of underlying libraries in the Clojure community than I ever did in the .NET community. I spent much of my University days working in C and assembly, and that is still the way I think about problems first, and I really could never bring myself to care about low level networking details even when working at that level - it simply doesn't matter to the problems I want to solve. In every area that is relevant to my work, the Clojure community has been a source of inspiration and information that has directly helped me solve more problems than I ever have before, and has led to me being more interested in the fundamentals of my work than ever before. I'm now going back and re-learning CS fundamentals that seemed pointless until the Clojure community showed me why they mattered in a practical way.
@bcbradley: I'm sure it's just something lost in translation - there are a lot of interesting things happening in Clojure, but it can be a lot to take in to really see the breadth and depth of what people are working on. Onyx and Jepsen are somewhat unique (at least from what I can see), ClojureScript is pushing a ton of awesome boundaries, Will Byrd said at the last Conj that the clojure community is the main place his research has found acceptance, Dragan Djuric is doing interesting work in high performance computing, and more and more. Hang out for a while and spend some time seeing what is happening and you may get a better sense of the community and where things are moving - maybe you'll find something that you can contribute to that will bring us closer to the ideal you are looking for - at the very least you should be able to better understand and verbalize the root of what you were trying to get to above.
@bcbradley which language do you feel most comfortable with? I believe you are "coming hot" to something that's new to you and you want to map patterns and ways you used to program to Clojure. You hope to find concrete examples, but you can't. If I am at least a little bit correct in my assumptions, I would recommend not to quit, and give Clojure a chance. As with anything new, you'll need time. One of the reasons you can't find examples could be because the way you know how to program could be very different in Clojure. The hardest part here is to ask the right questions and it just needs time and practice.
@bcbradley I agree with you that it is great to understand how TCP/IP works, for example, for two reasons: it is in fact needed for some problems (i.e. HFT) + it is just interesting to look under the elephants that hold the Earth, cause maybe the Earth is oblate spheroid and there is no turtle 🙂
@tolitius it isn't that, I just have some beliefs about what kind of environment people work best in and failed to communicate it
@shaun-mahood I'm sure I'll be able to communicate it better one day
I never noticed that (merge #{:a} #{:a})
returns #{:a #{:a}}
😮
merge is only defined for maps and boils down to reduce conj
so it's easy to see why that happens
into
also works fine. I was just surprised 🙂
Tidbit about into
for sets: The other day I wondered why one would want to use clojure.set/union
instead of into
and found that it's smart about conjing the smaller set into the larger set. Could be useful sometimes 🙂
Then again, it's an implementation detail. Oh, another reason would be to unionize more than two sets!
yes it is
ask away ☕
Excellent. Basically, I'm trying to leverage the Java SDK of Oracle Data Integrator, and being fairly new to Clojure, it's the first bit of interop I've tried.
I've got the SDK docs here: http://docs.oracle.com/cd/E28280_01/apirefs.1111/e17060/toc.htm
Created a lein app, put a symlink in the .../resources folder that points to the ODI jars folder and then referenced the jars as I've needed them in the :resource-paths of my project.clj.
if you want to access code, shouldn't that be in a source (not resource) folder?
I've managed to create some connection information objects, but when I try and create an actual connection I'm getting a NoClassDefFoundError, despite the class required being in the jar.
Oh, I'm not sure - I just googled "how to use local jars leiningen", or similar. It seems to work up to a point.
(ignore my previous comment, not sure that was relevant)
what's the exception you're seeing?
The error is CompilerException java.lang.NoClassDefFoundError: could not initialize class oracle.odi.core.DataSourceManager$1, compiling:(core.clj....
In the :import, I've recently added DataSourceManager$1 to try and fix the error, but to no avail.
have you tried importing just DataSourceManager?
I think the $
in the class name means that it's an inner class
pretty sure that you need to add something to the classpath
you could try taking leiningen out of the equation as an experiment
java -cp clojure.jar:odi-jar.jar clojure.main
then you can import classes from the repl
just try minimal example
that only creates a connection. That shouldn't require too many other dependencies, right?
you can also run lein classpath
should give you a good place to start
Interesting - I've just ran the code snippet above, and this time it's complaining about an Apache logging lib not being present.
There seem to be a few libs it's expecting that aren't in the cp - I'll go through them and add them one by one as needed and get back when I've exhausted them!
don't know if it is
I usually work with boot, not lein so maybe someone with more experience with leiningen can chime in
I suggested trying the pure clojure jar to isolate the issue and to find a minimal example
there could be an easier approach
No, I appreciate it - I'm currently doing the Brave Clojure book, so my knowledge and it accumulation has been pretty linear. This stuff is really helpful!
It's actually run without error now, but when I do (type odi-instance)
I get another error, seemingly another missing library!
I’ve used the spreadsheet read/write stuff in docjure
not offhand. Have you looked at the Apache POI docs?
@pesterhazy, I've got it (mostly) working with Leiningen now. Thanks for the guidance 🙂
@danp. No problem
Out of curiosity, what turned out to be the problem?
I have no idea, when I did everything outside lein, it was pretty clear about what was missing. When I had a "working" classpath, I just copied the relevant jars into :resource-paths.
sometimes when you try something in the repl, you get a partial exception. In that case you can type (pst)
to get more complete information
@jooivind It doesn’t look like docjure supports auto-size columns directly, but you should be about to call the autoSizeColumn method on the worksheet directly, via Java interop. I found a java example at http://www.programcreek.com/java-api-examples/index.php?class=org.apache.poi.hssf.usermodel.HSSFSheet&method=autoSizeColumn
hello everyone, im using compojure-api, and Im having doubts about de-structuring
(POST "/endpoint" []
:summary "info about endpoint"
:return {:responseField s/Num}
:body [my-entity
{:field1 s/Str
:field2 s/Str
:field3 s/Str}]
(some-func (:field1 my-entity) (:field2 my-entity) (:field3 my-entity)))
is there a way to avoid using the getters like (:field1 my-entity) (:field2 my-entity) (:field3 my-entity)
?@plins Yes, either using normal destructuring: :body [{:keys [field1 field2 field3]} {:field1 s/Str :field2 s/Str :field2 s/Str}]
or using Plumbing letk syntax which allows the same without repeating field names: :body-params [field1 :- s/Str, field2 :- s/Str, field3 :- s/Str]
@manutter51 i got it working by accessing the native java method, thanks!
Hi, I have a problem where I want to combine two lists in a specific way.
So lets say I have a fixed list of privileges:
(def privileges [:none :deny :grant])
and a list of rights:
(def rights [:save-table :save-tree])
Every right can be set one privilege. So for one right the result would look like this:
[{:save-table :none} {:save-table :deny} {:save-table :grant}]
And now comes the tricky part. For every additional right the rights can be combined with the privileges in every possible way. So for two rights the result would look like this:
[{:save-table :none :save-tree :none}
{:save-table :none :save-tree :deny}
{:save-table :none :save-tree :grant}
{:save-table :deny :save-tree :none}
{:save-table :deny :save-tree :deny}
{:save-table :deny :save-tree :grant}
{:save-table :grant :save-tree :none}
{:save-table :grant :save-tree :deny}
{:save-table :grant :save-tree :grant}]
I played around with permutations and tried some stuff using reduce and map, but just cannot find a good solution.
Any ideas?@rauh @tap Thanks, I totally forgot about for. Is there a way to use it with a dynamically sized list?
@sveri a 3-way for is the same as a 2x2-way for (where the second for
uses the result of the first for
). So you can just iterated with whatever construct (loop(?)) and use a 2-way for until you're done. Did that make sense? 🙂
@rauh I have not found a way to make it work, although, I mostly tried my way with permutations.
I managed to to use the cartesian product to build the privileges, but its the same problem. It takes several seqs as arguments, which is dependend on the number of rights in the rights vec: (comb/cartesian-product privileges privileges)
This is what I came up with for a dynamically sized rights vec:
(loop [counter (dec (count rights)) privs [:none :deny :grant]]
(if (zero? counter)
privs
(recur (dec counter) (for [p1 privileges priv1 privs] (vec (flatten [p1 priv1]))))))
(let [priv [:none :deny :grant]
rights [:save-table :save-tree]]
(apply cartesian-product [rights] (repeat (count rights) priv)))
@plins what's your use case for wanting to?
(ns bla.bla
(defrecord Benefit [^String cpf
^String username
^String email
.....]))
(defn my-func [^Double some-field ^bla/Benefit benefit] ....)
I mean without ugly prefix like java.util.bla.bla.bla
, is it possible to use something like :as
in import
like in require
? Can't find it in docs, sorry.
@netsu instead of (:import [java.util.bla])
, do (:import [java.util bla])
(note the space there at the end), now in that ns
you can refer to it simply as bla
@tanzoniteblack oh, thanks!
@plins generally type hinting is done to help the compiler make more efficient code by avoiding reflection, but if you're using a record created via defrecord, I'm not sure how you're writing your code that it might be doing reflection to have to figure out what class it's calling things with?
I feel like core.logic is a bit over the top for this, but maybe i'm wrong, I just don't have too much experience with it
@tanzoniteblack , right now im just annotating stuff for myself, afterwards i intend to switch to typed clojure
if you're just annotating stuff for yourself, either start with typed clojure, or prismatic's schema, or if you're using the 1.9 alpha use spec?
@pyr as long as you're planning on loading it into memory anyways, depending on the complexity of your "query", you probably just want to use filter
/`remove` to select your items. If the "queries" are rather complex, you might look into selecting them via https://github.com/nathanmarz/specter ?
pyr: I usually end up building an index using clojure.set/index and querying via get and for
hiredman: that sounds like an approach that would work for me, thanks, i'll look into that
@tanzoniteblack could you suggest how use it inside (ns
? Just
(ns local-scope-name
(:import [java.util.regex Pattern])
not working in expected way.netsu: How are you using it in your code, so I know "what the expected way" is?
with (import [java.util.regex Pattern])
it in scope. But when I simple
do (:import [java.util.regex Pattern])
in (ns
, it invisible.
can you please show me how you're calling Pattern
in the code?
not in the import
but where you're actually trying to use the Pattern
class for something
Currently code not working yet, so not sure about corectness. Here example:
(def dribbble (Pattern. "host(); path(shots/?id); queryparam(offset=?offset);"))
so 2 problems
1.) http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html doesn't have a constructor that just takes a String (which is what you're doing with (Pattern. "host...")
you have to use Pattern/compile
and 2.) Clojure has a built in reader for regexes; just use #"host..."
which avoids having to import Pattern
at all 🙂
but now I curios also about why I can't refer to java in :import
also... Clojure is still pretty new for me yet.
(ns data-playground.test
(:import [java.util.regex Pattern]))
(def test-pattern (Pattern/compile "string"))
that code works for me to define an ns
, import a Java class by name, and then refer to it later on
(again, you should use the #""
reader macro instead of Pattern/compile
in Clojure code, but for the sake of example)
@pyr Datomic works just fine for this, the in-memory connection works great, and the query engine is top notch
Odin will auto-index for you and saves you having to think about schemas: https://github.com/halgari/odin
@tbaldridge ah thanks
Good morning folks, I think I'd "doing it wrong" when i type things like this:
(filter #(select [ALL :thing #{2 22}] %) list-of-maps)
Well the fact that you used the words "sequence of nested blobs" says that this data is pretty unstructured. If you can fix that, accessing the data is often easier.
@arthur 🙂 you could do the whole thing in specter without the filter
, right? Just do (select [ALL ALL :thing #{2 22}] list-of-maps)
? So not sure if your "wrong" feeling is because it's an inefficient way to query the data (by looping through the entire list of maps for each individual query you have), or because you're mixing filter
and specter?
to me, it greatly depends for the speed thing. If you just need to get one or two things out of existing data you already have, it's probably more efficient to just do the specter or filter method. If you have a few hundred things you need to get, then you should probably make your data structure into something more efficient to query (like something with some kind of index). Also important: When/where is this data being run? In production code on a web api? Then you should be using an actual database, not a file. In some kind of one off script? Then who really cares as long as it finishes?
(after i broke it) @tanzoniteblack
lmao; fixing my old code from when Kurman and I were playing with specter originally then?
" In production code on a web api? Then you should be using an actual database, not a file. In some kind of one off script? Then who really cares as long as it finishes?"
Incidentally that's my biggest rational for not using Specter.
(select [ALL ...] ...)
returns only the portion being used to do the selection. so in the abve code it returns 22
not the map that under that key had the value 22
@arthur I think you're looking for selected?
(select [ALL (selected? <subpath>)] list-of-maps)
if <subpath> selects anything, then that element will be in the output vector
yes @nathanmarz that's the concept I was looking for
is there something like assoc for adding default values only if the field isn't already set?
@shader fnil works for this
or merge is good too
Hi - I'd like to take a value from a channel and dispatch it to one of a pool of channels, where the dispatcher picks the channel based on the value. The idea is to process incoming requests concurrently, but make sure that e.g. a given users requests are placed in the same queue so they are handled sequentially.
no ... reading up now :)
not sure that would fit...
you create a pub with a topic function something like (mod (hash whatever) 6)
then you spin up go loops that subscribe to topics 0 through 5
Potentially Seeing some large GC pauses when processing large lazy sequences. How can I start debugging that? Any common gotchas to look out for? The processing includes enriching the sequence from datomic and doing a http post.
@dominicm honestly, use transducers.
I used to have tons of issues with GC and lazy seqs, it's next to impossible to get that to happen with transducers
i have a project that's got a dependency on org.clojure1.3.0-alpha2, which isn't accessible - how do I find out which dependency (using leiningen) it is ?
@octo221 look at lein deps :tree
yeh I did that, but it didn't show me where the 1.3.0-alpha2 was
did you get an error @octo221 ?
yes, when I do lein deps (or lein deps :tree) I get Could not transfer artifact org.clojure:clojure:pom:1.3.0-alpha2 from/to clojure
(I'm using clojure 1.9.0)
- sorry I should have said it's fine on my local machine - I'm getting the error on a remote clone
oh, can you not see where the dep is coming from on your local machine then ? alternatively, put an :exclusions [org.clojure/clojure]
at the top-level of your lein project, and include the version you want explicitly in your :dependencies
maven repos can be configured in lein profiles or project.clj or settings.xml in ~/.m2/
if you are are setup to only use a maven repo you named "clojure", and that maven repo doesn't have the artifact you are looking for, the error would look like that
no I can't see where that dep comes from on my local machine with lein deps :tree
that could be it....
at some point, many years ago, the clojure artifacts had their own maven repo (not in central) and I bet lein defaulted to including that, and called it "clojure"
2.7.1
yes, that was a file system on http://build.clojure.org, which no longer exists (all those artifacts have been moved to maven central)
lein show-profiles on the failing machine, then look at each profile to see if it specs a repo somewhere
lein upgrade
Leiningen 2.7.1
@hiredman Love it. Thank you. Would one care about "consistent-hashing" here...?
no, hash + mod or some other way to map an open set of values to a closed set is enough, consistent hashing is a whole other thing that comes up in key value stores limiting the shuffle of data around when nodes are added or removed from the cluster
got it - it was Incanter - found by repeatedly deleting half the deps from the deps vector!! binary search
ah yes, incanter, the project that hasn't been updated in 3 years. Its surprising how often it turns up.
:exclusions [org.clojure/clojure] fixed that one
it's a shame about Incanter. I really want that project to go somewhere
and when you think people are using R
Clojure would be such a superior alternative
@tbaldridge 1 year ago 😉
off to sleep - thanks everyone for your help!
https://github.com/TheClimateCorporation/claypoole is another option
https://github.com/tolitius/lasync yet another option
is there a function that wraps a non-seq object in a list or vec, but leaves a seq alone?
@kanwei I would agree with @ghadi:
(defn worker [n]
; showing a blocking call here. use pipeline-blocking if your
; worker will block. This is for demo purposes only, to simulate
; real work
(Thread/sleep 1000)
(inc n))
(let [out (chan)
in (a/to-chan (range 8))]
(a/pipeline 8 out (map worker) in)
(<!! (a/into [] out)))
(the sleep to simulate some real work) -- change 8
above to 1
to observe the parallelism
I was sure someone would say that, but hoped it would be obvious in the context that it is an example to demonstrate something taking time.
the question isn't if it is obvious for us, the question is if it is obvious to people who may not be familiar with core.async and isn't aware that there are multiple kinds of pipelines. You shouldn't just run with an example of pipeline usage you see, there are variants of pipeline that behave differently and you should match the variant of pipeline to the kind of task
@hiredman Thanks again.
Anyone know any idiomatic way to create a map from a keys list
and a values list
I didn't know about that
awesome
sure beats: (apply hash-map (map #(list %1 %2) keys values))
Does someone know how to set the ns lookup path in the repl
?
Suppose I have a file in src/clj/app_name/core.clj
The namespace is app-name.core
In the repl, I can run:
(use 'clj.app-name.core)
(use 'app-name.core)
I would like to do this with a single command.
for reasons no one really cares about, dashes become underscores when mapping namespaces to files
thanks @hiredman but that is not the problem
there isn't a "path" you change, file names match the namespace name defined in the file, and clojure loads files from the classpath when you require or use the namespace
The repl base ns lookup path needs to be prefixed with clj
Can you explain more what you mean previously?
So can I prefix the classpath?
The build step is customized
We are building an SPA with cljs but our acceptance tests run on clojure
in the configuration of whatever build tool you are using, you are putting src/ on the classpath (or the build tool just defaults to it) but you want to put src/clj
the project.clj
is configured so lein knows to use src/clj
as the base source-path
for the clj build and src/cljs
as the base source-path
for cljs build
Not sure what you mean?
I have used multiple instances of the repl
lein figures out the classpath once when it start the repl, if you make changes to project.clj you have to start new repl processes to see them
CompilerException java.io.FileNotFoundException: Could not locate acceptance_test/utils__init.class or acceptance_test/utils.clj on classpath.
(use 'acceptance_test.utils)
I know
that was a typo
The problem is the repl is not using the same source-path
as the build step
Anyways, I got it to work. Thank you for your time
sorry to post this here but #testing channel seems to be not so active: https://clojurians.slack.com/archives/testing/p1489016676000099