clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
vlaaad 2020-07-31T06:08:05.435500Z

Shouldn't Clojure have some reader macro to requiring-resolve symbols? That way we wouldn't have to use resolve-fns like in clojure.core.server for every function that might be invoked both from code and from clj -X:alias

alexmiller 2020-07-31T12:47:27.469500Z

We’ve slowly working towards making vars effectively do this

alexmiller 2020-07-31T12:48:59.471600Z

So if you read a var quote it would resolve locally and be invokable. We now do this for serialization of vars but haven’t yet made the reader change but I have it prepped in a ticket somewhere

vlaaad 2020-07-31T12:52:26.473Z

ah, that’s wonderful

alexmiller 2020-07-31T12:56:00.476300Z

A very slow motion plan, maybe will come to fruition in 1.11 :)

🤞 1
vlaaad 2020-07-31T06:11:59.435600Z

Ah, they are read by edn, macro wouldn't work

vlaaad 2020-07-31T06:26:57.439600Z

Problem statement: clj -X:alias puts a requirement on entry-point functions to be able to accept only edn-read data, thus making their use both from code and from entry point clunky if they are designed to accept non-data as arguments.

cgrand 2020-07-31T08:03:33.465400Z

What do you mean by non-data? A resolved symbol (var or class or static field)? I think it’s a niche usage and you can work around it by having your own generic caller -X:call that will perform any resolution you wish before calling your actual target.

vlaaad 2020-07-31T08:11:28.465600Z

functions, for example

vlaaad 2020-07-31T08:26:44.467900Z

I think it’s super common to configure functions with other functions. It would be nice if I didn’t have to invent 2 different APIs for the same thing because one useful context of invoking my code has no way to pass a function

vlaaad 2020-07-31T08:31:35.468200Z

For example, -X (both in deps.edn and on the command line) could use reader tag val that does (comp deref requiring-resolve) … That would not compromise on simplicity — it’s still just edn data — and will help library authors to not complect their code with resolve-fn -s

seancorfield 2020-07-31T07:41:12.440100Z

What is "non-data" @vlaaad? I'm not sure that even makes sense...

seancorfield 2020-07-31T07:42:33.441500Z

And these are not "main" functions. -main accepts a sequence of strings. -X is for regular Clojure functions, which, last I checked, accept regular Clojure data... which is what you get from reading EDN... what am I missing?

vlaaad 2020-07-31T07:42:58.442Z

I want to create a function for people to use both as main and from code

seancorfield 2020-07-31T07:43:21.442700Z

Why? What problem are you trying to solve with that?

seancorfield 2020-07-31T07:43:48.443500Z

You can already invoke -main functions via the -m argument to clojure.

seancorfield 2020-07-31T07:44:21.444700Z

-X is a way to invoke additional functions -- non-main functions.

seancorfield 2020-07-31T07:45:06.445700Z

-m lets you invoke -main functions with strings. -X lets you invoke non-main functions with data.

seancorfield 2020-07-31T07:45:23.446500Z

Yeah, I've read it. Several times.

vlaaad 2020-07-31T07:45:24.446600Z

-X is entry point

vlaaad 2020-07-31T07:45:32.446800Z

it's a main

seancorfield 2020-07-31T07:45:40.447100Z

No. Not a "main".

vlaaad 2020-07-31T07:45:44.447200Z

a different kind of main

seancorfield 2020-07-31T07:45:47.447500Z

No.

vlaaad 2020-07-31T07:45:56.447700Z

okay, we have slightly different definitions of main

vlaaad 2020-07-31T07:46:07.448100Z

let's stick to entry point

seancorfield 2020-07-31T07:46:13.448400Z

-X lets you invoke any function -- even private ones -- with data.

vlaaad 2020-07-31T07:46:16.448600Z

both -X and main are entry points

seancorfield 2020-07-31T07:46:25.448800Z

No. You're wrong.

seancorfield 2020-07-31T07:46:46.449300Z

You think there's a problem here because you're starting from an incorrect set of assumptions.

vlaaad 2020-07-31T07:47:21.449500Z

why -X is not an entry point?

vlaaad 2020-07-31T07:48:50.449900Z

Alex's post literally says that...

seancorfield 2020-07-31T07:49:14.450400Z

"entry point" just means you can call any function. You're ascribing too much significance to that.

seancorfield 2020-07-31T07:49:28.450800Z

-main != "entry point" in this case.

seancorfield 2020-07-31T07:55:16.456300Z

Also bear in mind that -X allows you to call your -main function with strings from the command line (with appropriate quoting) -- this is a more general feature, based on Clojure-is-about-functions-and-data. -main is the old-school world of command-lines-are-strings thinking.

seancorfield 2020-07-31T07:55:59.457800Z

(it's 1 am here -- I'm off to bed!)

vlaaad 2020-07-31T07:56:12.458200Z

no, -X does not allow to call -main, because it will pass it a map, when -main expects a seq of strings

vlaaad 2020-07-31T07:56:33.458400Z

good night 🙂

seancorfield 2020-07-31T07:57:38.459700Z

Oh yeah... It's almost a superset. It's certainly a more general feature tho'...

seancorfield 2020-07-31T07:57:44.460Z

And good night.

seancorfield 2020-07-31T08:20:39.466600Z

So you could call -main if you only want to pass a single string 🙂

vlaaad 2020-07-31T08:21:08.467Z

Although I’m not surprised this works, I would expect it to be undefined behavior that we shouldn’t rely on :D

seancorfield 2020-07-31T08:21:47.467800Z

That is an interesting question -- is this defined/supported behavior. Hopefully @alexmiller can comment on that tomorrow.

alexmiller 2020-07-31T12:53:56.474Z

Disagree on the top here -X should pass only 1 map to a function (that this works here is a bug)

alexmiller 2020-07-31T12:54:45.474900Z

It’s a bug -X should only invoke functions of 1 map

➕ 1
alexmiller 2020-07-31T12:55:10.475500Z

It’s not a superset of clojure.main

dominicm 2020-07-31T12:56:37.476700Z

I suppose ":arg" is a more appropriate name, with there only being one

alexmiller 2020-07-31T12:57:00.477100Z

Well the idea is that it is a map of args

alexmiller 2020-07-31T12:57:16.477500Z

Kv args, not positional

seancorfield 2020-07-31T16:12:02.480100Z

Thanks for the clarification @alexmiller -- but if it's really "Kv args" as opposed to positional, shouldn't it be calling the function like (f :k 42 :foo "bar")? If you want to make it clear that it really is intended to pass a single argument :arg would make more sense than :args (I agree with @dominicm on that).

seancorfield 2020-07-31T16:13:25.481500Z

And given the intent is to call the function with just a single hash map, you probably want to enforce that before people start abusing it (exactly as I was doing, apparently, and in particular by using it to call -main with a single string argument)...

alexmiller 2020-07-31T16:15:24.483800Z

Oh, I will :)

seancorfield 2020-07-31T16:15:49.484200Z

And to @vlaaad: I was wrong and I apologize. We still disagree on "main function" as a definition I think but we agree on "entry point" and now it seems that they are disjoint features since you're not supposed to be able to use -X to call -main with a single string.

seancorfield 2020-07-31T16:32:28.487200Z

The other place, I can think of, where Clojure already uses :fn / :args is for function specs and :args there is explicitly a sequence of arguments (it catches beginners out that even for single-argument functions you need s/cat) -- so I really do think the singular :arg would be better here (or something more indicative of this being a single hash map argument). But I know we can often bikeshed on names so I'll leave it at that.

alexmiller 2020-07-31T16:34:58.487600Z

yeah, I am unswayed, not going to change

😸 3
vlaaad 2020-07-31T16:42:13.487700Z

No problem! It's hard to admit mistakes — you are a good strong person :)

1
vlaaad 2020-07-31T16:45:48.488200Z

I didn't want to call -main from -X btw, just tried to come up with an api for my function that is accessible from both these entry points... And from code... All at the same time

seancorfield 2020-07-31T16:47:46.488400Z

Yeah, now Alex has clarified the intent of -X it's clear they are disjoint entry points which is both good and bad. I think it means you're stuck with your cli in 10 lines approach to -main to allow calling into a common function.

vlaaad 2020-07-31T16:48:47.488600Z

I'm currently at 5 lines already :rolling_on_the_floor_laughing:

vlaaad 2020-07-31T16:49:09.488800Z

Gave up to simplicity of just edn

seancorfield 2020-07-31T16:49:47.489Z

At work we have a similar entry point -main in our <http://worldsingles.jobs|worldsingles.jobs> namespace: we pass in the fully-qualified name of a function to call and positional string arguments that are then packaged into a single hash map in -main which then calls the fq function. Although we parse the string arguments and use them are configuration to start a system Component usually, and those fq functions accept a system map -- they can't quite be called via -X at this point.

seancorfield 2020-07-31T16:50:03.489200Z

Deleting lines is always good 🙂