-
-
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
support C++ style default arguments? #1817
Comments
Is this different from keyword arguments (e.g. #485) with defaults? |
Was about to chime on with probable dupe of #485 myself. See also the Options package. |
Except I'm not suggesting keywords, just the "syntactic sugar" for multiple dispatch that @JeffBezanson mentioned in the thread. |
Ah. That would be a nice compromise along the road to full keyword arguments. |
Yep, this is totally separate from keyword arguments. Keyword arguments could coexist with this by using
|
I fully support this, this is basically the only reason I use the Options package. Having it be able to be so much less verbose would be awesome. |
Keyword arguments strike me as much more important and I'm not at all sure that having a short syntax for default values for positional arguments is worth that additional syntactic complexity. |
I kind of agree with Stefan that adding a semicolon is a source of confusion. To me this approach could be a nice interim solution, but I would find it confusing to have semicolons have actual semantic content in the language. |
@johnmyleswhite Don't semicolons already have "actual semantic content" in the language, e.g. for |
My objection is definitely not to using semicolon like that, but more to On Sat, Dec 22, 2012 at 6:05 PM, Steven G. Johnson <[email protected]
|
@StefanKarpinski I definitely sympathize with the instinct to say "no" to new language features. Add too much stuff, and the language turns into C++. In this particular case, because of Julia's Matlab heritage the use of optional trailing arguments for functions is very idiomatic for Julia (see e.g.
|
@stevengj: You're completely right that semicolons do have semantic content already in the language. And, now that I understand the proposal better, I quite like the idea of adding syntactic sugar to make it easier to use optional trailing arguments. But that liking depends on the fact that we don't have keyword arguments yet. What I worry about is that it becomes very strange to have a mixture of (1) defaults for positional arguments and (2) defaults for keywords separated only by a semicolon. I suspect that will be confusing to new users who wouldn't understand why all of the "optional" arguments aren't keyword arguments. It may just be my lack of familiarity with the C++ idiom, but I'd like all optional arguments to be keyword arguments as soon as that mechanism is in place. |
@johnmyleswhite So, when (if?) keyword arguments are supported, you would want functions like |
I would like that, but agree that it's such an extensive change that it may be infeasible. I also am not sure that we'll have keyword arguments anytime soon, which is why I'm now onboard for some sort of interim solution. |
Remember also that even if keyword arguments are implemented in Julia, optional positional arguments will always be supported because of multiple dispatch, so keywords can never supersede them entirely. That is, optional positional arguments are a feature you already have now, what I am suggesting is just syntactic sugar to make them a bit cleaner to code and document and to encourage them to be used in a consistent way. My feeling is that optional positional arguments are cleaner for functions like |
Feature added. |
Sorry to revive an old thread, but I don't find a discussion on why optional positional arguments are only possible at the end of positional argument list... do they have to? |
If you were to use such a feature, you'd have to be really careful to not introduce ambiguous method definitions, or we would need a new sense of method priority so that we can write code like foo(a=1, b=2) = a*b
foo(3) Pick the right definition of |
Yes, maybe it is best left to a macro, or with a different syntax to make it less easy to introduce ambiguity. I'm writing one currently wich uses |
It might be nice to support the C++ default-argument idiom. i.e. defining
would be equivalent to defining
as I find myself doing the latter a lot.
The text was updated successfully, but these errors were encountered: