clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
ikitommi 2019-07-01T11:16:20.223100Z

any plans in making this true?

(instance? java.util.function.Function (fn []))

ikitommi 2019-07-01T11:16:51.223400Z

would help a lot with the Java interop.

ikitommi 2019-07-01T11:25:35.223500Z

Currently writing code like this:

CompletableFuture
  (-send-response [response exchange]
    (.dispatch
      ^HttpServerExchange exchange
      SameThreadExecutor/INSTANCE
      ^Runnable (^:once fn* []
                  (.thenApply
                    response
                    ^Function (reify Function
                                (apply [_ response]
                                  (-send-response response exchange)
                                  (.endExchange ^HttpServerExchange exchange)))))))

alexmiller 2019-07-01T12:05:36.224900Z

We looked at it some for 1.10 and will probably take another swing at it in 1.11

alexmiller 2019-07-01T12:07:09.225600Z

I can’t search right now but there is a jira for it

ikitommi 2019-07-01T12:32:54.225800Z

found, https://clojure.atlassian.net/browse/CLJ-2365

alexmiller 2019-07-01T12:43:26.226100Z

that's the one, Ghadi's been working on it off and on

ghadi 2019-07-01T13:06:10.227Z

@ikitommi one thing we're thinking about is whether we can add the proper SAM interface to IFn automatically based on context. Not just for j.u.f.Function

👌 1
cfleming 2019-07-01T20:40:38.229600Z

@ghadi Do you mean doing SAM conversion for IFns? I would love that.

ghadi 2019-07-01T20:40:53.229900Z

it would be really cool but it's tricky

cfleming 2019-07-01T20:41:01.230200Z

I have no doubt.

cfleming 2019-07-01T20:41:20.230900Z

But 💯 from me.

ghadi 2019-07-01T20:41:43.231400Z

the goal would be to not have to specify SAM classnames or the SAM name itself

cfleming 2019-07-01T20:42:17.232300Z

I guess it’s tricky because of overload resolution?

ghadi 2019-07-01T20:42:41.232700Z

(.setUncaughtExceptionHandler (Thread/currentThread) (fn [t e] ....))

ghadi 2019-07-01T20:42:46.232900Z

if we could make that work ^

ghadi 2019-07-01T20:43:05.233400Z

the argument to setUncaughtExceptionHandler is a Thread$UncaughtExceptionHandler, which is a SAM

cfleming 2019-07-01T20:43:14.233700Z

How is that different from full SAM conversion?

ghadi 2019-07-01T20:43:16.233900Z

would be cool to auto-attach that interface to the fn

cfleming 2019-07-01T20:43:31.234400Z

Yes, it absolutely would.

2019-07-01T20:43:33.234600Z

so would only work if the fn is inline?

ghadi 2019-07-01T20:43:48.235100Z

yeah

ghadi 2019-07-01T20:43:59.235700Z

no way to generically do that through vars

cfleming 2019-07-01T20:44:11.236100Z

So you wouldn’t create wrapper interfaces in other cases?

2019-07-01T20:44:22.236600Z

could you do it with a defn if the user annotates it?

ghadi 2019-07-01T20:44:37.237200Z

there are a lot of different things to explore here 🙂

ghadi 2019-07-01T20:44:55.237900Z

you could dynamically spin adapters too, with indy

ghadi 2019-07-01T20:46:20.238700Z

(.setUncaughtExceptionHandler (Thread/currentThread) (fn [t e] ....)) for that to execute without a ClassCastException, the third argument must be a Thread$UncaughtExceptionHandler,

ghadi 2019-07-01T20:46:56.239100Z

whether it is an IFn too doesn't matter

ghadi 2019-07-01T20:47:21.240Z

my challenge is: can you do it without having to name that class?

ghadi 2019-07-01T20:48:05.241100Z

(which would mean you need to propagate the calling context of setUncaughtExceptionHandler into the analysis of the fn)

ghadi 2019-07-01T20:48:20.241600Z

or dynamically adapt fn with invokedynamic

cfleming 2019-07-01T20:48:41.242200Z

Surely you wouldn’t need to do that if you just created a wrapper class at the invocation point?

ghadi 2019-07-01T20:49:03.242500Z

that == which?

ghadi 2019-07-01T20:50:16.243600Z

the extra calling context analysis?

cfleming 2019-07-01T20:50:18.243800Z

(reify Thread$UncaughtExceptionHandler (uncaughtException [t e] (my-fn t e))

cfleming 2019-07-01T20:50:35.244300Z

i.e. you wouldn’t need to extend the analysis of IFn

ghadi 2019-07-01T20:51:06.244900Z

how do you know when to adapt vs. not?

2019-07-01T20:51:15.245400Z

again only with literals, maybe?

ghadi 2019-07-01T20:51:16.245500Z

if someone provides a Thread$UncaughtExceptionHandler

cfleming 2019-07-01T20:51:17.245600Z

Always adapt

ghadi 2019-07-01T20:51:19.245800Z

meh

ghadi 2019-07-01T20:51:25.246200Z

wrappers suck

cfleming 2019-07-01T20:51:29.246300Z

And let hotspot deal with it.

ghadi 2019-07-01T20:51:39.246600Z

you can write wrappers in userspace at your delight

cfleming 2019-07-01T20:51:51.246900Z

The problem is I don’t delight in doing it.

ghadi 2019-07-01T20:52:07.247200Z

ghadi 2019-07-01T20:52:14.247800Z

not a wrapper but some helpers ^

ghadi 2019-07-01T20:52:47.248400Z

with a wrapper, who looks up the proper classname @cfleming?

cfleming 2019-07-01T20:53:12.248600Z

How do you mean?

cfleming 2019-07-01T20:54:05.249200Z

Ugh, I really have to run, sorry, but I’m very interested in this.

ghadi 2019-07-01T20:54:12.249400Z

what triggers the emission of (reify Thread$UncaughtExceptionHandler (uncaughtException [t e] (my-fn t e))?

ghadi 2019-07-01T20:54:16.249600Z

np

cfleming 2019-07-01T20:54:53.250900Z

Right, the problem in a dynamic lang is knowing what you have, I guess.

ghadi 2019-07-01T20:54:54.251Z

just wanted to say that extending IFn to j.u.function.Function is only 1% of the problem

ghadi 2019-07-01T20:55:00.251200Z

which was suggested earlier

alexmiller 2019-07-01T21:00:43.251800Z

if it was easy, it would already be done :)

ghadi 2019-07-01T21:01:30.252300Z

there probably exist 0 use cases of things that need the functional interface && IFn

ghadi 2019-07-01T21:01:52.252800Z

when you want to interop with the functional interface, you no longer care about IFn