-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implicit kwargs object? #2475
Comments
What you're really asking for is Haskell's as-patterns. See http://www.haskell.org/tutorial/patterns.html I agree, as-patterns are needed. edit: Also, never refer to those generated variables in your code. |
A cleaner version for doing this is: foo = (kwargs) ->
{bar, baz} = kwargs
console.log "kwargs: #{JSON.stringify kwargs}" LiveScript lets you name destructuring arguments using a foo = ({bar, baz}:kwargs) ->
console.log "kwargs: #{JSON.stringify kwargs}" |
I'm on the fence about this.. If it was implemented as a feature, what would be wrong with it? Currently i agree, don't use Wouldn't But none the less, currently i agree.. you have no idea if CoffeeScript will decide to change |
@epidemian: That's LiveScript's implementation of as-patterns. @leeolayvar: Possibly, but you would have to remember complex rules regarding name generation. That's not a feature you would add to your language. Explicitly naming these temporary constructs via as-patterns is far superior. |
One thing that CoffeeScript already is naming deconstructed object properties, like: foo = ({bar: thebar, baz: thebaz}) -> But it doesn't let you name that whole deconstructed object. |
@michaelficarra: Fine with me :) @epidemian: I like your cleaner version. When i want the object name, i think i'll do that for now :) |
@michaelficarra Oh also, as-patterns such as |
It doesn't, unless you have a value before, ie |
@leeolayvar: No, you're thinking of list destructuring. As-patterns give a name to the object being destructured so both the inner members and the outer container can be referenced. |
Nice :) |
I'm afraid I'm going to be a stick in the mud about cluttering up function signatures as usual. The explicit name of the argument with the destructing below looks best to me. |
Would it be possible to expose an implicit
kwargs
,kwargs2
, etc object?For example, currently if you want the kwargs the only .. "clean" way to do it is as follows..
Now, the same thing can be achieved without defining kwargs, by using
_arg
, such as..But i don't think
_arg
,_arg1
,_arg2
, etc, is descriptive enough.. do you? I'm likely in the minority, but wouldn't renaming_arg
tokwargs
or_kwargs
be more intuitive?I mean, if you know
_arg
refers to a hidden object variable name, then it is easily made sense of, but if you don't.. the user is left wonder which_arg
it is referring to.The text was updated successfully, but these errors were encountered: