-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit arrow functions #499
Comments
Wild idea, I guess we could support this:
(require '[squint.core :refer [=>]])
(=> [x] (inc x))
clj-kondo could be easily configured using lint-as
Another more slightly verbose idea without inventing new syntax:
(fn ^:=> [x] (inc x))
…On Sat, Mar 30, 2024 at 10:53 PM Martin Klepsch ***@***.***> wrote:
To upvote this issue, give it a thumbs up. See this list
<https://github.com/clj-kondo/clj-kondo/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc>
for the most upvoted issues.
*Is your feature request related to a problem? Please describe.*
Arrow functions have different semantics than regular JS functions. For
better host interop it might be worth considering a way to support them.
via #498 <#498>
*Describe alternatives you've considered*
- metadata
- new fn-style macro
—
Reply to this email directly, view it on GitHub
<#499>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACFSBXYD7253PTONQO4CZDY24X6TAVCNFSM6AAAAABFP3K5ICVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIYTMNRXG4YTENY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Didn't (=> ...)` mean something entirely different in Clojure (pipe operator? wasn't there a TC39 proposal to add that to JS?) Or maybe some kind of per-file/per-project pragma? This complicates things... New syntax |
|
I just had a question. If within |
Even in JSX you don't know if you will need the More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions |
That's because of the ambiguity of the word "property". I don't mean JS properties, just the properties of a thing in the general sense. My bad, could've expressed that more clearly - differences aside,
Awesome! I support that. |
Shortness isn't the main point here though. The main reason you would have an additional way in squint to produce |
I'm going to throw a wild idea out here: could |
That also crossed my mind and worth exploring. Technically it's possible, but could there be any breakage doing this? |
There are a few more restrictions on
So the compiler would have to check for these things as well... and there may be cases where the user wants to do one or the other depending on the closed over value of |
Just writing my thoughts down... I think that the first one is the same thing we've been talking about re: {a: () => "foo"} it works just fine, but you won't get the desired behavior if you want to use re:
The only technically ambiguous case in that list would be constructors. I'm not sure how much weight to give that. Another potentially ambiguous case is when you actually want to use the surrounding function someMethod() {
return () => { this.someOtherMethod() };
}
let o = {someMethod, someOtherMethod() { console.log("foo") }};
let f = o.someMethod();
f() The above ought to print This could be expressed two different ways:
This also presents why arrow functions are less useful in ClojureScript; the default way of accessing function someMethod {
let that = this;
return function () { that.someOtherMethod() };
} Anywho, I think I've talked myself out of automatically deciding which syntax to use, and instead would vote for an unambiguous syntax (just like JS); I like |
Re
and
are both possible and behave differently. The JS user can control this behavior explicitly by using an arrow function or not. Re
... and then indeed I read that you already talked yourself out of auto-arrowing :) |
I think I'll do the following: first support it via metadata. If it then becomes annoying because people use this all the time, then we'll introduce a |
To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.
Is your feature request related to a problem? Please describe.
Arrow functions have different semantics than regular JS functions. For better host interop it might be worth considering a way to support them.
via #498
Describe alternatives you've considered
The text was updated successfully, but these errors were encountered: