-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make .a syntactic sugar for i->i.a #22710
Comments
|
Ah, that wouldn't be good. Just out of curiosity, what is an example package like that?
That doesn't seem type stable, whereas both a Given the |
I'm confused, why is
Of those proposed I do prefer 2b as well, though I'm still not really a fan of it. |
I have no idea, I just looked at the output from |
Agree that we should keep When you look at code_warntype for |
This is a little sketchy to me. It's sort of introducing a global namespace of field names. What kind of accessor is |
We already have a global namespace of field names, as does every other object-oriented language. In any case, those issues apply equally to |
Those are called without a leading It still seems really weird and confusing to me to be omitting the object from which you're getting the field. What's wrong with |
-1 from me. |
For my Query.jl use case it is just too verbose (e.g. see this comment).
I hear you, that worries me too. I'm not particularly wedded to this syntax, but so far I couldn't think of anything better, and (at least from my perspective) the benefits of having something for this use-case outweigh the costs, even if we end up using the |
If we adopt @JeffBezanson's suggestion for dot overloading, then In my mind, the main use for this is for things like
(Is there a problem that dot overloading doesn't solve? 😉 ) |
Another possibility would be to use Or |
I definitely feel your pain about verboseness though, @davidanthoff . Perhaps we just have to resort to having a macro that goes in front of a query than relying on changes to Julia syntax though. |
I think it's highly valuable to try to think of generally-usable syntax that makes macros less necessary. |
OK sure, I am all for bending Julia's syntax to be more accommodating to data analysis :) I was just trying to be sensitive to the valid complaints that Julia syntax should not become the symbol soup of Mathematica etc. |
I would still like to have a terse function syntax based on |
|
Here's a previous discussion with a bunch of good examples to check against: #5571 (comment) |
Note that @davidanthoff can already use the |
I really like the For my use-case it does kind of rely on reducer functions having a combined map-reduce method that accepts a map function as an argument. Currently many reducer functions don't have such a method. Over in #20402 @StefanKarpinski has one item "Reducers APIs. Make sure reducers have consistent behaviors – all take a map function before reduction; congruent dimension arguments, etc." I guess if that happens for 1.0 all is good and we would have a pretty elegant solution for the Query.jl use-case (and many others). Thanks all for the great ideas :) |
How about |
Eh maybe inconsistent if |
I thought a bit more about this, and I think I could actually solve the original issue in Query.jl that motivated this issue in a much more elegant way if we had dot overloading a la #1974. So from my point of view we could close this issue and just add one more cheer for #1974. Essentially, I could then extend the |
I'm going to close this issue because I can essentially solve this in a really good way for Query.jl with the new dot-overloading. Having said that, one crazy idea might be to add such a dot-overloaded method to any |
Wouldn't that be implicit vectorization of the kind we've moved away from? |
Hm, I'm not sure? It would unify the user API for arrays-of-struct and struct-of-array containers in the table world. I assume But in any case, clearly not 1.0 stuff. |
To me, a table-like thing is semantically always an array or collection of structs. It might be stored as a struct of arrays, but should have the same API. So for example |
It would be convenient to make
|
Why do you need it in the type domain? IPO on 0.7 will propagate symbols as constants to any inlined functions. From there you can lift them to the type domain yourself if you really wish. |
Yeah, I've worked pretty heavily trying to get constant propagation to work. Even with the changes in |
See for example https://discourse.julialang.org/t/is-this-pure/8050/6 |
And #26826 seeks to address constant propagation through varargs. |
Another issue is that constant propagation doesn't survive keyword arguments and named tuples. |
Oh and here's another option: define a custom type with overloaded dots, something like
|
I think this has been suggested in various places before (i.e. I deserve no credit for this idea), but I couldn't find an issue for it, so here it is.
The motivation for something like this are
@group .. into
statements in Query.jl. With those one often gets an array of named tuples, and a super typical next step is that one wants to run some aggregation function over one specific field of the named tuple. SayA
is an array of named tuples, then I might want to write something likemean(map(i->i.b,A))
to take the mean of columnb
.Idea 1 would be to simple make
A..b
syntactic sugar formap(i->i.b,A)
. The aggregation expression would then be written asmean(A..b)
.Idea 2 is based on an observation by @JeffBezanson in #21875:
Which is probably somehow related to this issue, but I'm not entirely sure.
I think maybe idea 2a might be something like
.b.(A)
instead ofA..b
? Not sure, more putting this out here for discussion. The aggregation would then be written asmean(.b.(A))
. I find that a bit confusing, though.Maybe idea 2b could be to still have
.b
meani->i.b
, and then make sure that all aggregation functions likemean
etc. take an anonymous function as their first argument, so that one could always write these aggregations as saymean(.b, A)
.queryverse/Query.jl#121 in Query.jl currently implements
A..b
within queries, but I'm a bit hesitant to add too much special syntax in Query.jl, especially around things where we might end up with some other solution in baseUPDATE: It seems pretty clear that idea 1 is not a good one, so I changed the title of this issue to refer to idea 2b, which seems the most plausible one.
The text was updated successfully, but these errors were encountered: