Skip to content
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

Formal Parameters and Pattern Matching #362

Closed
yfeldblum opened this issue May 6, 2010 · 3 comments
Closed

Formal Parameters and Pattern Matching #362

yfeldblum opened this issue May 6, 2010 · 3 comments

Comments

@yfeldblum
Copy link

CS already has nice recursive pattern matching on arrays and objects, which is fantastic. This feature works for LHS parts of assignment expressions. This feature should also work for formal parameter lists. Example:

myfunc: ([ xyz, abc..., k ], { top, bottom, middle }) ->
  alert (xyz + top)
  abc + bottom - (k * middle)

myfunc [ 1, 2, 3 ], { top: 1, bottom: 2, middle: 3 }
@jashkenas
Copy link
Owner

A very nice idea, but I'm afraid we've tried to stay away from complicating parameter lists in the past. There have been proposals for named parameters, default-valued parameters, and variations of these pattern-matched parameters.

I think that the party line should continue to hold. Parameter lists should be simple lists of names, and it's up to your function body to de-structure or manipulate them as you see fit.

There's a good argument to be made that, at the point when you've specified a method signature like the above, where you're expecting a primitive array of a certain structure, followed by a primitive object of a certain structure, you should really be passing a full-blown object in, that can encapsulate that state.

So thanks for the ticket, but closing as a wontfix. There's no additional flexibility that this gives you that couldn't otherwise be accomplished by a pattern match at the start of your function (which is probably what we would transform it into, if we added it).

@yfeldblum
Copy link
Author

Jeremy, thank you for the feedback.

@jashkenas
Copy link
Owner

Hey, feel free to pop into #coffeescript if you'd like to discuss it further.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants