This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-05
Channels
- # announcements (10)
- # beginners (59)
- # calva (172)
- # cider (13)
- # clj-kondo (1)
- # cljdoc (10)
- # cljs-dev (4)
- # cljsrn (65)
- # clojure (144)
- # clojure-europe (2)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-nl (14)
- # clojure-spec (26)
- # clojure-uk (91)
- # clojurescript (75)
- # core-async (53)
- # cursive (11)
- # datomic (16)
- # fulcro (42)
- # graalvm (29)
- # graphql (9)
- # kaocha (3)
- # leiningen (22)
- # off-topic (26)
- # qa (1)
- # re-frame (3)
- # reagent (7)
- # reitit (10)
- # rewrite-clj (56)
- # robots (1)
- # shadow-cljs (107)
- # spacemacs (10)
- # specter (5)
- # sql (15)
- # tools-deps (39)
- # vim (11)
is there a short syntax for selecting namespaced keys of off map? e.g.: {:foo/one 1 :foo/two 2 :three 3}
I want to do (select-keys m [:foo/one :foo/two])
but without having to repeat :foo
or even better, select all keys that start with :foo/
without even listing them one by one
@ag Not exactly what you are asking, but in the context of destructuring:
user=> (def m {:foo/one 1 :foo/two 2 :three 3})
#'user/m
user=> (let [{:foo/keys [one two]} m] [one two])
[1 2]
But, presumably you are looking for a shorter version of
(select-keys m (filter #(= "foo" (namespace %)) (keys m)))
I hate typing. I dunno how people even deal with semicolons and commas and all that crazy garbage in other languages
Type one namespaced keyword, then copy/paste for the others?
I guess with data-readers you could define #foo[:x :y :z]
to become [:x/y :x/z]
or whatever
we've talked about extending the namespaced map literal syntax to vectors #:foo[:x :y :z]
but then the question is what about sets #:foo#{:x :y}
? gross.
deps.edn and private git repositories... any advice? getting: com.jcraft.jsch.agentproxy.AgentProxyException: connector is not available:
https://clojure.org/reference/deps_and_cli#_git_configuration might help
platform?
Hello, how can I stream System.out.println() to the Clojure REPL? I am using a java class compiled with leiningen, and I want to see its log when calling it in the REPL.
(System/setOut (java.io.PrintStream. (org.apache.commons.io.output.WriterOutputStream. *out*) true))
(.println System/out "hi")
Is everyone using Integrant
together with Duct
or are you also running it standalone?
If I have clj and cljc file for same namespace, in what order are they compiled? Same for cljc/cljs.
platform specific is always preferred
so for clojure usage, I don't think you would get cljc compiled/loaded at all
cljs is more complicated as prob different stories for macro and non-macro
ah, so it only compiles one
yeah - they are alternate versions of the same namespace
in clojure, it will look for a .class first (if newer than clj or cljc), then .clj, then .cljc
thank you for that info
hello guys, I have a reservation system which works with agent
, so people can't reserve at the same time. But sometimes it stops working, it gives me no exception, and it doesn't restart. how is this possible?
agents can fail and won't restart
well, on my client-side, when people are reserving the server responds that the agent needs restart, like I wouldn't have setup the error handler.
there are lots of options for how errors and restarts are handled
but presumably you have a whole stack of code between the client and the agent, how do you know the failure isn't in there somewhere?
so, the error-handler! doesn't handle everything? @alexmiller
I don't have any of it in my head atm, I just know there's lot of stuff there that I use so infrequently that I have to re-read the source
@hiredman because the error is specific to the agent, and because I log the errors and the restarts, and sometimes restarts doesnt happen, only the error
and honestly, approx 0% of users use this stuff so it wouldn't surprise me if there were unsurfaced bugs
how are you configuring the agent wrt error-handler and error-mode?
@hiredman, I log in the database for certain functions. like restarting the agent. And when agent restarts I put the error in my logs. In the case when restarting doesn't happen, my error is logged, but is an empty string
@alexmiller, well it is in my snippet, I set-error-handler! after defining it
the default error-mode of an agent is :fail, not :continue (unless there's an error handler)
not sure how that changes if you set the error-handler after the fact
I put it back, i didnt want chaos
but it sounds like you are getting an error (the error handler is running) and something is going wrong in your error handler
that's the code without modification
exceptions thrown in the error handler itself are ignored and lost
you've introduced a race here by restarting in the future - restarts are ignored if the agent is not in a failed state
I would have to study all that code more closely to really think about the concurrency aspects of this
so, I take out future and it should be fine?
it may or may not be fine, depending, but it will take care of the empty string thing
it would take me a lot more time to answer that question, and I don't have it atm
I never did concurrency before, this is my first approach on this topic.
But it will restart then, that's what matters, I guess.
why not just use error-mode :continue?
then the agent will automatically restart?
in general (depending on the database) you will be much better off using your database features to keep things consistent in the face of multiple writers
(set-error-mode! reservation-queue :continue)
presumably at some point you want this running on multiple machines, at which point the serialization you get from agents doesn't exist
@alexmillerdidn't know such thing existed, thank you very much
if you read the docstring for agent
and some of the other functions around it, I think that might help
@hiredman No, this project will stay with 22 shops, so I guess I won't need nothing more sophisticated. But I am trying to learn more about the topic, I also enjoy it more than the frontend. ๐
@alexmiller Thank you, duly noted. If it weren't for a stackoverflow topic, I wouldn't even used future, so yes, next time I start with the docstring.
The string above will not trigger any custom data readers
If I understand correctly, a custom data reader could cause a string like {:foo #my-tag 1 }
to read #my-tag 1
as an Integer
, but that is a different string.
Even that would read 1 as a Long first
And your data reader could convert it to whatever
Warning: most kinds of Clojure arithmetic done on an Integer will not return an Integer.
That's ok. Our app has config files in EDN. Some of those config maps need to be passed via a Properties
map to a Java library. Java libraries typically have methods declared that take an int
and not long
.
if you use Clojure to call those methods, it usually does the right thing
isn't Properties always string->string?
Hmm, lemme see. I definitely get an exception due to a Long being passed instead of an int.
Properties extends Hashtable so you can abuse it by using the parent class methods to put other stuff in it
right, but it's not going to be via Properties... at least not via standard methods https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#getProperty(java.lang.String)
@kenny all the kafka configs are strings
I know that one specifically
I'm not doubting something wants an int and gets a long, but it's not kafka via properties
I passed {"
as part of the kafka config and it threw the cannot pass a Long exception. This fixed it {"
{"
is canonical
int happens to work
@kenny usually I have a function that turns a clojure hash-map into string/string pairs then puts it into a Properties map
Yeah, should probably add helper function for that, especially now that I know it's a nasty api.
hi, is it possible to require two different versions of a library and use it at the same time?
not in any simple way, no
@noisesmith what would be the trick then?
isolated classloaders iirc
everything I've tried or heard about it makes it seem frustrating
A classloader hierarchy along the lines of the one OSGi uses, where peer classloaders do not delegate to their parents when looking for a loaded class. Been a long time since I did this, so the details are very fuzzy.
and making it work with Clojure iirc requires a pretty intimate understanding of how clojure extends the runtime classloader - my knowledge of this stuff is not very deep, maybe someone else can offer more detail
I know there was at least one fork of clojure for the express purpose of working with isolated classloaders
right - the fork I mentioned was for usage with OSGi
because clojure as is wasn't compatible
I think it's less about not delegating to parents, and more about creating two (or more) inheritance trees
Delegation might be the wrong word. I remember that it allowed a "child" classloader, instantiated for a service, to access classes "sideways" from other peers, without first looking in the parent. Or something like that ๐
That allowed for an additional security layer, whether a class was exposed outside its service, etc
oh, that's more than I know about it
It was strange stuff in a way, I ported 2 implementations to a "java on the chip" box my company at the time made.
you can achieve this isolation in Java by using a post delegation classloader. however, clojure's dynamic classloader explicitly shares a class cache with all other dynamic classloaders
thanks guys, quite interesting, I also heard that it is possible to have clojure repl running along with a pure java application running under Tomcat and invoke commands from the repl, so , in theory we could write java code, compile it and call from clojure repl without restarting the embeded tomcat server, am I correct?
not exactly - depends what you're doing
that's not really a clojure question
depends if you're making new classes (then you need a classloader that knows how to load them) or redefining (there are paths to this in the jvm but it's not trivial to do in general)
in general, I'd say you should not do any of that. there are probably better ways to accomplish whatever goals you have
like, don't write code, just make new instances using existing classes. and make more flexible frameworks if you need more dynamicity (clojure is great for that via its var system)
Hey guys, there is any Microservices example in Clojure? But I want something full fledged and mostly ready to production. I want to see some real project of a medium size or bigger. Not really interested in small examples, but I guess I wonโt find this...
Small projects are fine to understand stuff, but it really doesnโt teach anything about how a ready to production code is working and should be
the idea is, I'm currently working with an old java framework that requires too much time to build, and also, its too coupled so , you never knows how it will behave xD , so I was looking for a solution for faster feedback
@vachichng why not make a small set of stubs that call into clojure from the framemwork, then redefine the clojure stuff as needed while developing?
the stub should only need to change if you have a major architectural design, and the clojure stuff it calls is freely redefinable without a restart
I've used this pattern for jsvc for example https://github.com/noisesmith/clj-jsvc-adapter
thanks @noisesmith I will have a look at it!
the code is very small - it just makes a tiny implementation of every method needed, that uses the clojure API to look up a var with a "magic" name and call it https://github.com/noisesmith/clj-jsvc-adapter/blob/master/src/java/org/noisesmith/Cljsvc.java
it expects an ns with start
, init
etc. as vars, then loads the ns and attempts to call them
so my hunch is you can do the same with your old java framework - give it methods (probably easier to just do in java), and just make sure everything those methods do can be freely redefined in a repl
then no more restarting the framework for code changes