News for hackers. Stuff that matters.
Re:Clojure 1.11 planning by dancek on Tuesday October 08, 2019 @07:51AM (#21191186)
What parts of compatibility are missing? The interop works just fine, as with all other Java.

  ; example: Stream.of(1,1,2,3,5).map(x -> 2*x).collect(Collectors.toList())
  user=> (.. (java.util.stream.Stream/of (to-array [1 1 2 3 5]))
             (map (reify java.util.function.Function 
                    (apply [this x] (* 2 x)))) 
             (collect (java.util.stream.Collectors/toList)))
  [2 2 4 6 10]
Of course it's not practical to convert lists and functions to their Java counterparts like that, but if you need to work with Java objects it's possible.
Re:Clojure 1.11 planning by logistark on Tuesday October 08, 2019 @01:20PM (#21194612)
I think first class support would remove a lot of boilerplate in that code. For the purpose of writing that, i prefer to write it directly in Java.
Re:Clojure 1.11 planning by keymone on Tuesday October 08, 2019 @03:00PM (#21195817)
Why wouldn’t you prefer writing it directly in Clojure?

    (map #(* % 2) [1 2 3 4 5])
Even less boilerplate, even more signal/noise.
Re:Clojure 1.11 planning by airstrike on Tuesday October 08, 2019 @10:53AM (#21192940)
Slightly off-topic, but as someone who's normally using Python / R, my hands feel tired just from thinking about typing all of that
Re:Clojure 1.11 planning by ARandomerDude on Tuesday October 08, 2019 @11:00AM (#21193011)
In practice, you wouldn't. You'd import at the top of the file, then type `Stream/of` instead of `java.util.stream.Stream/of`.

I almost never use Java directly though because there are so many great Clojure wrappers.

Re:Clojure 1.11 planning by Uhuhreally on Tuesday October 08, 2019 @12:56PM (#21194313)
In Clojure that's:

  (map (fn [x] (* 2 x)) [1 1 2 3 5])
  => (2 2 4 6 10)
Re:Clojure 1.11 planning by agumonkey on Tuesday October 08, 2019 @12:40PM (#21194144)
so no Java Function to clojure Function automating mapping ? do people use macros to make it nicer ?
Re:Clojure 1.11 planning by dancek on Tuesday October 08, 2019 @05:00PM (#21197217)
Not out of the box, probably because java.util.function.Function seems like an afterthought in a strictly object-oriented language while Clojure has first class functions. In practice you don't interop with Java very much, let alone functional Java (as Clojure itself is a much better fit). But if it was useful, it'd be easy to write helpers for converting functions back and forth.
Re:Clojure 1.11 planning by Uhuhreally on Tuesday October 08, 2019 @12:53PM (#21194285)
you'd use Clojure not Java for an example like the above
Re:Clojure 1.11 planning by Scarbutt on Tuesday October 08, 2019 @01:34PM (#21194754)
I think the context is when doing interop.
Re:Clojure 1.11 planning by Uhuhreally on Tuesday October 08, 2019 @02:17PM (#21195284)
yes but I got the feeling the grandparent was confused so I tried to clarify that the only reason for the verbosity is interop - the Clojure code is much more concise than the Java - the interop code is like listening to a speech being translated between English and Spanish
Re:Clojure 1.11 planning by serpix on Wednesday October 09, 2019 @12:15AM (#21199971)
functions. Macros are a super weapon and their use is reserved for very special cases. One reason is macros can't be composed as functions and also readability goes out the windows.