3 ms·
Even for hobbyist stuff, Lisp’s lack of libraries can be frustrating. I wanted to build some useful things as I was teaching myself Common Lisp, but there eithe
by Mediterraneo10 6y ago
Even for hobbyist stuff, Lisp’s lack of libraries can be frustrating. I wanted to build some useful things as I was teaching myself Common Lisp, but there either was no library at all for what I wanted to do, or on Quicklisp there was just some bare-bones library that offered some meagre
functionality but warned that most things hadn’t been written yet.
- vikramkr 6y agoI guess thats what something like clojure is supposed to fix? Interop with Java to give you access to that world? Not sure how that plays out in the real world though
- danielam 6y agoIn my experience, quite well, though I have not had to reach for Java libraries that often, either because Clojure equivalents exist, or because someone else had already put a wrapper around the Java library.
- billfruit 6y agoYes, but clojure toolchain system seems a bit brittle to me, especially the rather onerous use of leiningen etc.
- ithrow 6y agoInterop with Java to give you access to that world? Yes but it's a big time sink, you waste time thinking on how to wrap library, and for some libs you end hitting some blockers cause Clojure's interop is not that smooth, ending up writing two wrappers, one in Java(to make the lib usable from Clojure without pulling your out) and one in Clojure. And I'm talking about ad-hoc use of Java libs, writing a more idiomatic wrapper is a lot work. The Clojure ecosystem is pretty much abandonware at this point, even for high profile libraries. In languages with big ecosystems, you simply just use the lib and get work done, no cognitive overhead, no time sink.
- grzm 6y agoClojure Java interop has been pretty painless in my experience. https://clojure.org/reference/java_interop https://clojure.org/reference/java_interop It's pretty easy to translate things like import java.time.Duration; import java.time.Instant; import java.util.Date; //... Instant nowInstant = Instant.now(); Instant fiveMinutesAgo = nowInstant.minus(Duration.ofMinutes(5)); Date nowDate = Date.from(nowInstant); to (import '(java.time Duration Instant)) (import '(java.util Date)) ;; static method call with / (slash) (def now-instant (Instant/now)) ;; instance method call with dot. First arg is the instance (def five-minutes-ago (.minus now-instant (Duration/ofMinutes 5)) (def now-date (Date/from now-instant)) Implementing interfaces and extending classes are a bit more involved, but I haven't had to do much of that in my experience, and when I have had to, that's been pretty good, too. Here's an example implementing the AWS Lambda RequestStreamHandler interface https://github.com/aws/aws-lambda-java-libs/blob/master/aws-lambda-java-core/src/main/java/com/amazonaws/services/lambda/runtime/RequestStreamHandler.java https://github.com/aws/aws-lambda-java-libs/blob/master/aws-... (ns com.example.hn.handler (:gen-class :implements [com.amazonaws.services.lambda.runtime.RequestStreamHandler]) (:require [clojure.java.io :as io])) ;; implement the RequestStreamHandler handleRequest method (defn -handleRequest "echoes request" [_ input-stream output-stream _context] (let [w (io/writer output-stream) event (slurp input-stream)] (-> w (.write event) (.flush)))) That's probably shorter than the equivalent Java implementation.
- Scarbutt 6y agoShowcasing Clojure's Java interop with the java.time library is IMO pretty disingenuous. That's a pretty good modern library with a great API conformed completely of immutable classes, most Java libs are not like that.
- grzm 6y agoI can only show things I use, and these are things I do every day. (I also wanted a succinct example to post on the forum that people might be familiar with.) Please do share counter examples, as I'm genuinely interested. One of the more complicated things I've had to do was parseBest as part of DateTimeFormatter, which takes a TemporalQuery as an argument. It has a solution like this: https://clojurians-log.clojureverse.org/clojure/2019-09-06/1567785740.204500 https://clojurians-log.clojureverse.org/clojure/2019-09-06/1... I've also worked with JDBC libraries to wrap driver-specific features. JDBC drivers have been around for a long time, and driver-specific stuff can vary in how well it's designed. I've also used jna through Java from Clojure when I was just starting out, which wasn't all that hard for a newbie to the language. From your comments in other Clojure-related threads we've participated in, it sounds like your experience is much different from mine, but often lacks in specific examples. Without seeing those, it's hard to know what you're describing. If you think Clojure isn't the bees knees, that's perfectly fine. I think readers would benefit from knowing specifics of what you've found frustrating.