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

implicit array suggestion #1190

Closed
dbrans opened this issue Mar 9, 2011 · 4 comments
Closed

implicit array suggestion #1190

dbrans opened this issue Mar 9, 2011 · 4 comments

Comments

@dbrans
Copy link

dbrans commented Mar 9, 2011

Commas are reserved for function arguments and array elements. However, if there's no function, is there any harm in interpreting an expression like "3, 4, 5" as an array? Would it be useful?

examples off the top of my head:

x = 3, f(2, 3), 5

x: 3, 4, 5

(3, 4, 5).slice 0

x for x in 3, 4, 5

And there's no reason it shouldn't work like function arguments, where only the first comma is mandatory:
x,
f 3
z

Thoughts?

@michaelficarra
Copy link
Collaborator

There are some glaring ambiguities here. Do you mind writing up a grammar or something to better illustrate your suggestion?

@jrus
Copy link

jrus commented Mar 30, 2011

What's the benefit? Just saving two characters? (and not even in the (3, 4, 5).slice 0 case, since you can already write [3, 4, 5].slice 0 or even [3..5].slice 0.)

OTOH, cleaner dereferencing assignment would be a slightly bigger advantage. You could do e.g.: a, b, c = b, c, a

@ghost ghost assigned jashkenas Apr 21, 2011
@jashkenas
Copy link
Owner

Too many ambiguities for this one, I'm afraid.

a = 1, 2, 3 # array
a 1, 2, 3 # 3 args
a(1, 2, 3) # 3 args
a (1, 2, 3) # array?

@dbrans
Copy link
Author

dbrans commented Apr 21, 2011

a (1, 2, 3) # definitely 1 arg: array.
Just as
a (o = {}; o.b = 3; o) # is 1 arg
and
a(o = {}; o.b = 3; o) # is 3 arg

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

4 participants