but I guess it needs updating. With MacroTools.jl, this is rather easy to write from scratch, too.
I am skeptical about the utility though, compare
@p f(x, ...)
x -> f(x, ...)
which is just 2 more keystrokes, nests well, and is free of corner cases. But I am skeptical about the whole tidyverse approach, it is extremely convenient for small examples but does not compose well.
Well, 5 more keystrokes if it became a proper language feature (as in the PR), which would be a third of the whole expression. I would actually really like to see this feature as it adds, I think, a lot of convenience when sticking to a more functional programming style.
This is only true in usage examples with a few short argument names—which is what people in the “numerical computing” side of the Julia community tend to encounter. On the “data analysis” side, which we have traditional not served as well, it’s very common to have more and longer names. For example:
The point being that every time someone claims that this “only saves a few characters” they’re apparently willfully ignoring the fact that the savings is proportional to the number and length of the argument names, which is not fixed and will be much larger in some kinds of use cases than others.
I may be missing something, but in a closure, the argument names are up to the user, aren’t they? Longer names can of course be more descriptive, but if that is desired, _ and _1 and the various other proposals for partial application syntax are probably not wanted anyway.
(Also, I am not willfully ignoring anything, just disagree about a technical point.)
Even with one-letter names, the extra typing still scales with the number of arguments and there are many situations where one doesn’t particularly want to use single-letter names for clarity. Which is what makes the “it’s only two more keystrokes” response disingenuous—it’s only two extra keystrokes in the minimal case. It’s easily dozens of keystrokes in completely reasonable and realistic situations. There’s also the related issue of passing keyword arguments with the same name as the variable that’s passed, e.g. f(x=x) which is also dismissed as being “only two more keystrokes” but of course, that’s just the minimal case and it’s many more keystrokes in perfectly reasonable situations like:
I was actually looking for this sort of thing last night.
This is a big deal in data science because I have to have multiple people read my scripts without having a great idea of how Julia works. I need the names to be very explicit so they at least now what I’m acting on. I could always just make a comment in my script but then whoever reads it would have to learn how I code certain variables and Julia syntax. Unlike other mathematics I can’t just use sigma and then everyone will know what I’m talking about
I agree with this. But I still don’t understand how this goal meshes well with the _ and _1 syntax of partial application. It is my understanding that one can have either informative (longer) variable names, or the partial application syntax (for those variables), but not both at the same time. If I misunderstand, please clarify.
You are right. I would frame it differently then: for the very simple cases which are most commonly used (closures with one or two arguments), the cost is small. For more complex cases, a the partial application syntax saves more keystrokes, but runs into other issues of complex/unclear semantics (as demonstrated by the discussion of #24990 and the related PRs/issues).
Just to clarify: I was initially very enthusiastic about partial application syntax because think it would save quite a bit of typing. Then having carefully read all of the above discussions, I now think that all the proposed rules have to be quite complex because of various corner cases.
It is possible to come up with well-defined semantics for these, but it would mean that I would need to remember some nontrivial rules about the _ syntax. This would make me treat it like precedence: I know that the rules exist, I know that they are well-defined, but I still don’t rely on all them since I would have to keep looking them up. So I would probably limit myself to the simple cases (like _ + y), in which case a closure is not that much of a bother.