Fork me on GitHub

I just published the first release of sweet-array, an array manipulation library for Clojure with sweet array type notation and more safety by static types! • Defines a concise and intuitive array type notation, and provides a generic array constructor which can be used for any types and dimensionalities • Automatically inserts type hints for arrays based on the results of type inference, which reduces the cases where users have to add type hints manually

🎉 5
🍬 1
nice 2
Noah Bogart15:11:03

this is cool! any particular reason you didn’t wrap/re-export alength?


this seems very useful for when you want better utilities for working with arrays but you might not want to pull in all the dependencies of dtype-next - cool stuff!


@UEENNMX0T Hi, thanks! The only thing we can do for that is type checking, so I didn’t give it much priority. But from the completeness point of view, it might be good to add it. @UFTRLDZEW Yeah, dtype-next is powerful and useful but could sometimes be overkill. This library can be used for little Java interop things like varargs method calls.

👍 1
Alex Miller (Clojure team)16:11:32 1.5.640 is now available (all fixes in both CLJ and CLJS): • On put to closed channel, commit handler to allow pending alt ops to be cleaned up • Fix ioc-macros/return-chan registers a callback with incorrect arity • Tweak docstring in pipeline-async • Fix a/map with empty chan vector hangs Several of these are important bug fixes and I would recommend updating.

clojure-spin 17
🎉 4
Alex Miller (Clojure team)16:11:36 0.3.214 is now available: • Add support to transform trailing maps on instrumented functions into kvs (really only relevant for 1.11.0-alpha1+)

Alex Miller (Clojure team)16:11:04

(same change applied to spec 2 as well, but no releases there)

borkdude 5
🎉 4

By the way, do you have any info about the state / roadmap of spec2?

Alex Miller (Clojure team)19:11:16

Clojure is now available: • Add functions to parse a single long/double/uuid/boolean from a string • Add NaN? and infinite? predicates • Add random-uuid • Add namespace, wrappers for java.lang.Math • Make Clojure Java API javadoc text match the example • Update clojure.string/split docstring regarding trailing empty parts • Clarify clojure.core/get docstring regarding sets, strings, arrays, ILookup • Add definition to reify docstring • map-invert should use reduce-kv and transient • Support IKVReduce on SubVector • Update dep to spec.alpha (0.3.214)

💯 38
🎉 43
rich 19
🚀 7
clojure 8
💜 3

@U04V70XH6 are you already running it in production ;-)?


We'll have it in QA by end of day. Our next backend production build will be next week 🙂


(a bunch of folks are off this week due to Thanksgiving)


Looking forward to retiring some of our conversion/parsing functions in favor of these new built-in ones!

Vincent Cantin03:11:44

The parse functions are right on time for this year's Advent of Code 💯


@U8MJBRSR5 How do those make it easier? You can mostly just call the parse* JVM functions. A bit more effort since you'd need try/`catch` but it doesn't make anything completely new possible, just more convenient.


That function isn't the same at all:

user=> (parse-long "\n 18 15 \n")
user=> (parse-long "\n \"18\" 15 \n")
user=> (require '[clojure.edn :as edn])
user=> (edn/read-string "\n 18 15 \n")
user=> (edn/read-string "\n \"18\" 15 \n")


Some functions in the math namespace result in reflection warnings:

Loading /Users/ikoszo/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar!/clojure/java/math.clj... 
Reflection warning, /Users/ikoszo/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar!/clojure/java/math.clj:362:3 - call to static method abs on java.lang.Math can't be resolved (argument types: unknown).
Reflection warning, /Users/ikoszo/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar!/clojure/java/math.clj:373:3 - call to static method max on java.lang.Math can't be resolved (argument types: unknown, unknown).
Reflection warning, /Users/ikoszo/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar!/clojure/java/math.clj:384:3 - call to static method min on java.lang.Math can't be resolved (argument types: unknown, unknown).
Reflection warning, /Users/ikoszo/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar!/clojure/java/math.clj:556:3 - call to static method scalb on java.lang.Math can't be resolved (argument types: double, unknown).
Is this by design?


We had this with Math/abs previously and ended up using clojure.math.numeric-tower/abs instead.


(in cases where we couldn't type-hint the call due to having to handle both long and double)


Woo I originally suggested convenience number parsing specifically for advent of code :smiling_face_with_3_hearts:

Alex Miller (Clojure team)13:11:07

@U08BJGV6E no - how are you seeing that?


(set! *warn-on-reflection* true), then load the ns into the repl


can't repro.

$ clj
Clojure 1.11.0-alpha3
user=> (set! *warn-on-reflection* true)
user=> (require '
Perhaps you're using java 17?


require won't reload an already loaded ns


I went to the actual ns file and did a load to repl editor command


user=> (require ' :reload)


I haven't tried but I'm assuming re-evaluating those fns one by one would result in the same


What Java version are you using


let me try on 11


I also can't repro with Java 17 but I have seen one reflection issue before when upgrading when another same-arity/different-type overload got added.


Clojure 1.11.0-alpha3
user=> (set! *warn-on-reflection* true)
user=> (ns
  ^{:author "Alex Miller",
    :doc "Clojure wrapper functions for java.lang.Math static methods.

  Function calls are inlined for performance, and type hinted for primitive
  long or double parameters where appropriate. In general, Math methods are
  optimized for performance and have bounds for error tolerance. If
  greater precision is needed, use java.lang.StrictMath directly instead.

  For more complete information, see:
  (:refer-clojure :exclude [min max]))
nil> (defn abs
  {:doc "Returns the absolute value of a (long or double).
  If not negative, a is returned, else negation of a is returned.
  If a is Long/MIN_VALUE => Long/MIN_VALUE
  If a is a double and zero => +0.0
  If a is a double and ##Inf or ##-Inf => ##Inf
  If a is a double and ##NaN => ##NaN
  See: "
   :inline-arities #{1}
   :inline (fn [a] `(Math/abs ~a))
   :added "1.11"}
  (Math/abs a))
Reflection warning, /Users/ikoszo/Library/Application Support/JetBrains/IdeaIC2021.3/scratches/math.clj:362:3 - call to static method abs on java.lang.Math can't be resolved (argument types: unknown).
on java 11


I can see why this could happen - inside the abs fn, there is no information about a that could help the compiler choose the right method to call


yep, that reproduces it for me


If I open the ns in Cursive, it will highlight this


Due to our previous adventure with abs I was really interested how this would be solved in the new ns, which is why I started poking around


It's the same thing some array based function in clojure.lang.RT, you can't really avoid reflection here unless you enumerate all possible input types and make special cases for them


but then you're basically already doing the reflection yourself


Well, I don't have a solution, but it was surprising to see a reflection warning from a core ns. And according to Alex it wasn't intentional

Alex Miller (Clojure team)13:11:08

This call is inlined, so it doesn't actually matter


unless you're using it as a higher order function for example


but then you can still add a type hint in the surrounding code


While I'm not familiar with the concept of inlining in clojure, wouldn't it still result in reflection use when invoking (Math/abs a)?


Not if you do: (let [a 1] (Math/abs a))


since the type of a is known in that context


What if the only thing I know about a is that it's a number?

borkdude13:11:15> (let [a 1] (abs a))
1> (defn foo [a] (abs a))
Reflection warning, NO_SOURCE_PATH:1:15 - call to static method abs on java.lang.Math can't be resolved (argument types: unknown).


Then the compiler doesn't have enough information to select the method


One could also wonder what ( 1) gives over (Math/abs 1), I mean, it's not like the interop was hard to type?


At least we get auto-complete for those functions in editors that have not so good Java support ;)


I'd consider it a good value add if could solve those reflection warnings 🙂

Alex Miller (Clojure team)14:11:35

As has been discussed in #clojure-dev and the ticket, discoverability and avoiding interop were motivations

Alex Miller (Clojure team)14:11:52

The numeric-tower impl relies on multimethods and boxing and other stuff that are not a good base for performance


Good points. Making these wrappers also helps beginners that are not so familiar with the JVM (discoverability)


ah, thanks for the pointer, I see there's a very similar discussion happening there


Would it make sense though to point out in the docstrings that reflection warnings are somewhat expected for these fns?


I think making it clojure.math and the same in CLJS would help discoverability and beginners even more. So :thumbsup: from me so far on that idea.