This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-10
Channels
- # announcements (14)
- # bangalore-clj (1)
- # beginners (89)
- # calva (166)
- # cider (33)
- # clara (12)
- # clj-kondo (1)
- # cljdoc (8)
- # clojure (101)
- # clojure-austin (1)
- # clojure-colombia (7)
- # clojure-dev (14)
- # clojure-europe (5)
- # clojure-hamburg (10)
- # clojure-italy (9)
- # clojure-nl (31)
- # clojure-spec (4)
- # clojure-uk (39)
- # clojurescript (17)
- # clojutre (3)
- # code-reviews (16)
- # cursive (72)
- # data-science (1)
- # datomic (81)
- # duct (8)
- # emacs (4)
- # figwheel-main (1)
- # graalvm (2)
- # jobs (9)
- # kaocha (21)
- # lambdaisland (2)
- # luminus (4)
- # off-topic (35)
- # re-frame (1)
- # reagent (101)
- # reitit (4)
- # ring-swagger (5)
- # shadow-cljs (17)
- # sql (40)
- # tools-deps (4)
- # vim (28)
I am seeing this: https://github.com/puredanger/clojure-from-java A java interface backed by Clojure. Is there an example of a Clojure Protocol backed by Clojure but used from Java? EDIT: I am guessing the protocol will have to have type hints - but will it suffice?
Starting even smaller, the following does not seem to work (compilation error):
public boolean isAwesome() {
IFn isAws = Clojure.var("mylibraryinclojure.myns", "abooleandef"); // in a CLJ library (def ^boolean abooleandef true)
IFn deref = Clojure.var("clojure.core", "deref");
System.out.print("isAWS " + deref.invoke(isAws)); // prints true
return true; // OK
return deref.invoke(isAws); // KO
// error: incompatible types: Object cannot be converted to boolean
// return deref.invoke(isAws);
// ^
}
Likely the deref.invoke method returns type Object, not boolean.
to invoke a protocol from Java, you'll want to call through the same named interface that is generated
that protocol will always have all Object in method calls and returns
this is usually a poor interface from a Java user perspective (it will also lack javadoc, etc)
generally I find if your goal is a high quality Java interface, you should make that interface yourself, in Java
the repo above is mine btw
I've used that technique on a couple of real projects with success
it's better - you can at least type things properly
I notice a big problem/trend in software for quite some time, and this problem is not really limited to clojure uniquely in anyway (and for non-library code, I'm often quite guilty of it, but think i'm a little more on base for library code), but that's "completely nonsensical names for different packages" (or, names that have no meaning). I would much rather read something like com.acme.net.web.routing
and com.example.net.web.routing
than compojure or ataraxy or bidi, a bunch of names that don't give any insight into whats in it. Is clojars the best location to get a list of "clojure package that does 'foo'"? (other than search engines)?
https://clojars.org/search?q=ring+routing - almost 1000 different results to look through - "html templating" is equally as bad
though doesn't cover every library published to Clojars, just a curated set
I think the java convention has 2 big benefits - its easy to tell whose responsible for a library, and it lends itself to actually hosting documentation at that url
Does clojars have an API or a page where you can choose sort of results? like, sort by last publish date, or sort by total downloads/popularity?
I'm writing a plugin which takes a collection of namespaces to be required dynamically. What would you name the argument to that function? namespaces
, nss
, libs
, libspecs
, or something else? In this case it doesn't make sense to provide libspecs as they are required purely for spec registration side effects, not for referring or aliasing into a namespace
There is an API which does take some Lucene search query params. Not sure how well it is documented, but I think cljdoc was using it, at least for a while
seems good too
Does Clojure have an installer type setup for Windows (similar to pacman -S clojure
for Arch Linux)? or is the only Windows option signing up for an oracle account and downloading the jdk by hand, and then getting the clojure jar? After many years away from windows, I tried to set up leiningen on a windows VM - it was a very bad experience
@m131 Check out #clj-on-windows and folks will be happy to tell you how they do stuff...
Scoop is very popular as a package manager on Windows, I gather.
That certainly makes it easy to install any number of different JDK variants.
I installed the Zulu JDK 8 + JavaFX bundle that way over the weekend -- to test REBL on Powershell.
And there's a Scoop bucket for Clojure (unofficial, but it uses the official Powershell alpha installer).
very cool, thanks, I'll give that a look - seems a lot better than random cnet links if I want to skirt around the oracle sign up form
There are lots of OpenJDKs out there -- no need to deal with Oracle's at all these days on any platform.
The Scoop bucket listed there also makes it easy to install Joker, a linter for Clojure (which has a lot of editor integrations).
if I wanted to write a gui with the widest-reach in clojure, is seesaw, being swing oriented, the best candidate? I really like cljfx, but the openjfx dependency seems very flakey between java versions - bundled in some of them, not present in others, available as a maven dependency here or there
Is there a good place to find and ask macro wizards questions (or is this it)? I'm struggling with defining a macro that checks whether an argument is passed is a type (in Joker; "Class" in Clojure/JVM) before deciding on the expansion.
If your macro argument is anything other than a literal object, then you are going to have problems
My use case might narrow those cases down to only the useful ones: I want to extend the repl's doc
function to support e.g. (doc Boolean)
, i.e. documentation of types.
Doing things the obvious (to me) way, I can't get (doc Boolean)
to work, because for some reason the (type? name) ...
test I've inserted before the final (resolve name)
in the cond
list (which matches Boolean
and then tries to (var ...)
it) doesn't recognize it as a type.
Because the reader reads it as a symbol, and it isn't until it is evaluated (compiled and executed) that you get a Class object
In my Clojure repl I've done (defn type? ^Boolean [x] (= (type x) java.lang.Class))
, which works in isolation on the few test cases I've tried.
But if I call that in a macro, it doesn't work, and I've tried various things that don't seem to get it to work.
Oh, I think I see what you're saying: capture the result of (resolve name)
(instead of just testing it) and test that result with (type? ...)
?
Well, this is promising:
user=> (defmacro mm [n] (let [r (resolve n)] (if (type? r) (println "is a type") (println "not a type"))))
#'user/mm
user=> (mm +)
not a type
nil
user=> (mm Integer)
is a type
nil
user=> (mm Boolean)
is a type
nil
user=>
Okay, this seems to work, in that I get a nil
Meta map (because I haven't yet added the code to populate that for any of the builtin Joker types) instead of an error when I do (doc Boolean)
:
(defmacro doc
"Prints documentation for a var, type, or special form given its name,
or for a spec if given a keyword"
{:added "1.0"}
[name]
(if-let [special-name ('{& fn catch try finally try} name)]
`(#'print-doc (#'special-doc '~special-name))
(cond
(special-doc-map name) `(#'print-doc (#'special-doc '~name))
(keyword? name) (println "Keywords (spec) not yet supported")
(find-ns name) `(#'print-doc (#'namespace-doc (find-ns '~name)))
(resolve name) (let [x# (resolve name)]
(if (type? x#)
`(#'print-doc (meta ~x#))
`(#'print-doc (meta (var ~name))))))))
Thanks!!!(It's not the Clojure doc
, though -- that's the one currently defined by Joker. I recently PRed the (find-ns name)
clause to support printing documentation for namespaces.
(And yes the code looks kinda ugly to me, because of the duplicate (resolve name)
being done in that case. Not sure how best to address that though....)
For anyone curious about what I was trying to do, here's the resulting PR: https://github.com/candid82/joker/pull/262
It's so nice that these days in almost half of the job ads I see which are located near me (Helsinki, Finland) there's also Clojure listed as a language which they are using
(clojure.string/replace "a" #"a" "\\")
Why won’t this replace a
by \
?
per the doc string:
For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern. If you wish your replacement
string r to be used literally, use (re-quote-replacement r) as the
replacement argument.
user=> (clojure.string/replace "a" #"a" (clojure.string/re-quote-replacement "\\"))
"\\"
regexes are inherently an area where host semantics matter and may differ
but you can also do:
(clojure.string/replace "ab" #"(a)(b)" (fn [[m group1 group2 :as v]] group2))
do differ
Hey all, I can't find if there is a way to have lein run tell me the return value of my -main
function. Is there a way?
Right now I know I can do it by either running in the nREPL or if I use System/exit
, but the latter will kill an nREPL solution as well as my function.
It’s void, so no
There is no return value
The function literally does not return a value (it’s a Java void return)
I often have -main call a function that does the work and use that for testing etc
@emccue either https://github.com/plumatic/schema or clojure.spec will work for you (I'm prefer schema, as it's easier to map it to the shape of the external data, but it's a personal thing)
see that makes sense to me kinda within functions, but i don't know how to use those tools to actually manage what happens if it goes wrong
but i don't know how to tell the user "sorry, your name field was > 140 characters" without doing it all manually
Gotcha. I've seen projects which "humanize" schema (or spec) errors - worth checking them out. This might be a good jumping off point https://github.com/datil/schema-rosetta