cljs-dev

souenzzo 2024-11-30T02:59:47.017579Z

Patch submitted @dnolen. I preferred to split into parse-ns-excludes/parse-ns-excludes-impl functions. Otherwise it would format a huge chunk of code

❤️ 1
dnolen 2024-11-30T12:32:45.022439Z

re: Clojure 1.12 method values in ClojureScript. After some more though there is possibly a wrinkle, mostly around interop. We do need to know the arity - for Closure / CLJS that's pretty easy to infer (we already have the machinery). But stuff that Closure won't see is a problem, so we do need :param-tags - but in our the case is the types aren't so meaningful.

dnolen 2024-11-30T12:34:58.921669Z

I think for interop method values you'll see a lot of ^[Object Object] etc. - not a huge deal - but just noting to see if other folks have thoughts.

borkdude 2024-11-30T12:35:21.077099Z

@dnolen ^[_ _] is also valid in 1.12

dnolen 2024-11-30T12:35:47.724619Z

ah ok I missed that? was that written down somewhere?

borkdude 2024-11-30T12:37:15.980919Z

https://clojure.org/reference/java_interop#paramtags

borkdude 2024-11-30T12:37:44.707469Z

> Parameters with non-overloaded types can use the placeholder _ in lieu of the tag.

borkdude 2024-11-30T12:38:07.519869Z

How useful are method values for CLJS anyway?

dnolen 2024-11-30T12:39:56.276939Z

other thing, Math String are implicit namespaces, but I think this will probably go away and they will be more like implicit refers as they are in Clojure - I pondered the js$ thing and to be honest I'm not a huge fan wrt. language built-ins going back to 2001. Math String Object even Function all provides useful stuff that would be convenient if you just get at them directly, js/ is really a kind of silly thing - they aren't not really foreign - fully covered by Closure for the obvious reasons

dnolen 2024-11-30T12:40:28.160059Z

I think method values will be useful, again for built-ins I never found the current status quo to be very pleasing

borkdude 2024-11-30T12:41:14.867809Z

you can already do (map Math/sqrt [1 2 3]) in CLJS

dnolen 2024-11-30T12:41:24.373439Z

it's also harder to predict future utility for shared libs .cljc - but I think probably be useful.

dnolen 2024-11-30T12:41:46.019559Z

but w/ a misfeature IMO - implicit namespaces re Math/sqrt

borkdude 2024-11-30T12:42:14.567579Z

well, (map js/Math.sqrt [1 2 3]) then

dnolen 2024-11-30T12:42:42.645849Z

that's ugly in two different historical ways

borkdude 2024-11-30T12:43:11.080109Z

how would you write that without an implicit namespace + js and with method values? I think I'm not getting it yet

dnolen 2024-11-30T12:44:03.185089Z

nothing would change Math/sqrt - just that Math wouldn't be an implicit namespace anymore

dnolen 2024-11-30T12:46:03.004629Z

but also stuff like (map ^[_ _] Object/assign seq1 seq2) would work

borkdude 2024-11-30T12:50:32.431799Z

Why would you need param tags for this though?

cljs.user=> (def Object js/Object)
#'cljs.user/Object
cljs.user=> (map Object.assign [#js {}] [#js {:a 1}])
(#js {:a 1})

dnolen 2024-11-30T12:52:52.394749Z

sorry you're right that case will work, but new is a problem

thheller 2024-11-30T12:53:14.935949Z

my take on this is that the Classname/method syntax makes no sense in CLJS given that JS doesn't care what class method comes from to invoke it. So if anything the only thing needed is a generic "interop" way for calling an instance method on an object, without needing to specify the Classname.

thheller 2024-11-30T12:53:40.796879Z

the Object.assign case is a bad example since this is not really about calling an instance method, rather a static method

borkdude 2024-11-30T12:54:19.418649Z

(map .length ["foo" "bar" "baz"])
? ;)

souenzzo 2024-12-03T12:33:10.840039Z

what if js/.length

👍 1
dnolen 2024-11-30T12:54:56.093599Z

to be clear I'm only interested in more or less doing it the same way (as Clojure)

dnolen 2024-11-30T12:55:12.923409Z

for example for people doing something very serious they very well might define Java/Closure classes the

dnolen 2024-11-30T12:55:29.107909Z

same way and just not want to deal w/ reader literals

dnolen 2024-11-30T12:59:51.276509Z

(map String/substring strs ints) - we don't need param tags in this specific case because of externs, but I think in general you do need them.

thheller 2024-11-30T13:01:52.983289Z

what for ... JS doesn't have type based overloading or "reflection" based method calling. we just call the things with arguments and let JS figure it out. This isn't the JVM where it wants to know the exact signature before calling it (or use reflection)

dnolen 2024-11-30T13:02:11.699429Z

(also not making any decisions yet, but probably I missed stuff, and also happy to collect concerns whether I agree/disagree at the moment)

dnolen 2024-11-30T13:03:29.435819Z

that's not really true for ClojureScript, we do need to know the arity - performance

dnolen 2024-11-30T13:03:36.646719Z

that's one of biggest optimizations

dnolen 2024-11-30T13:04:16.331899Z

so JS doesn't care because it'll happily make yr program go slow

dnolen 2024-11-30T13:10:29.832729Z

but I do get some of these points about the utility

dnolen 2024-11-30T13:11:03.558229Z

1. new as fn does seem useful - it's annoying that construction is static in a lot of cases

dnolen 2024-11-30T13:11:14.519659Z

2. static methods seem useful - and fixes old yucky cases

dnolen 2024-11-30T13:11:35.313679Z

3. I agree that instance methods are probably not so useful, but I believe in completeness around method values

thheller 2024-11-30T13:15:51.485839Z

I mean realistically I cannot think of a case where the Classname is actually relevant to the JS code that needs to run. so for completeness-sake it could just be ignored and just use the name part of the symbol

thheller 2024-11-30T13:17:43.058949Z

I don't think a world where AnythingGoesHere/foo is good design, but forcing the user to actually figure out and get a "class" equivalent so the compiler has something to resolve to isn't good either

thheller 2024-11-30T13:29:29.731509Z

I'd second the @borkdude example above, but its a bit problematic because (-> "foo" .length) is already allowed and valid but nothing like a method value. not sure this is actually a problem since macro expansion happens before analysis, but still kinda confusing for one thing to become something else entirely depending on context.

dnolen 2024-11-30T13:29:40.847039Z

gotta step away for a bit, but keep the thoughts coming

dnolen 2024-11-30T13:30:33.848749Z

(like I said people might rarely use 3. and I don't think this is huge problem, w/ 1. 2., doing 3. is not that much more work)

dnolen 2024-11-30T17:15:41.124259Z

@souenzzo patch looks ok https://github.com/clojure/clojurescript/pull/240

dnolen 2024-12-02T13:03:33.029789Z

applied to master

🤩 1
dnolen 2024-11-30T18:06:31.330059Z

One failed test https://clojure.atlassian.net/jira/software/c/projects/CLJS/issues/CLJS-2292?jql=project%20%3D%20%22CLJS%22%20ORDER%20BY%20updated%20DESC%2C%20created%20DESC - easy to fix, let me know if you want me to handle it

souenzzo 2024-12-01T22:40:26.894139Z

Fixed 🙂