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

[NFR] Support for list() #18

Open
sergeyklay opened this issue May 13, 2017 · 12 comments
Open

[NFR] Support for list() #18

sergeyklay opened this issue May 13, 2017 · 12 comments

Comments

@sergeyklay
Copy link
Contributor

From @mruz on January 24, 2014 11:43

It would be nice to can use list():

var width, height;
list(width, height) = getimagesize(value["tmp_name"]);

Copied from original issue: zephir-lang/zephir#105

@sergeyklay
Copy link
Contributor Author

From @wapmorgan on February 20, 2014 19:52

Agree.

@sergeyklay
Copy link
Contributor Author

From @lstrojny on February 20, 2014 23:34

Wouldn’t proper destructuring be more desirable?

left, right = getimagesize(...}

@sergeyklay
Copy link
Contributor Author

From @nkt on February 21, 2014 0:1

@lstrojny 👍
I think there is no o need to add new keyword.

var a, b, c;
let c = [1, 2];
let a, b = c;

@sergeyklay
Copy link
Contributor Author

From @nkt on September 7, 2014 13:20

So, i've added support in parser for syntax like:

let [a, b, c] = arr;

@phalcon, @ovr, @mruz what do you think about this syntax?
I've tried to add support for

let a, b, c = arr;

But failed.

@sergeyklay
Copy link
Contributor Author

From @ovr on September 7, 2014 13:31

Vote for

let a, b, c = arr;

@sergeyklay
Copy link
Contributor Author

From @nkt on September 7, 2014 13:33

@ovr I agree with your vote, but do u know how to add this in parser?

@sergeyklay
Copy link
Contributor Author

From @ovr on September 7, 2014 13:40

@nkt
Nope 😄

@sergeyklay
Copy link
Contributor Author

From @mruz on September 7, 2014 15:5

let [a, b, c] = arr;

Is enough for me.

@sergeyklay
Copy link
Contributor Author

From @thaJeztah on September 7, 2014 15:58

I may actually prefer let [a, b, c] = arr.

It may be just me, but I would (at a glance) interpret

let a, b, c = arr

as

let a = arr; let b = arr; let c = arr;

The extra brackets would hint at 'something extra is performed here' when scanning code.

@sergeyklay
Copy link
Contributor Author

From @phalcon on September 7, 2014 19:49

I'd prefer

let (a, b, c) = arr;

We can use this syntax in the future to assign the same value to every index in the array:

let [0, 1, 2] = null;

@sergeyklay
Copy link
Contributor Author

From @aschwin on November 26, 2014 15:52

Is there a decision already for this issue?

@flyingangel
Copy link

flyingangel commented Apr 22, 2018

Just want to add my bit..

Stolen from ECMAScript 6 (JS) :
http://es6-features.org/#ArrayMatching

let [item0, , item2] = arr;  // => let item0 = arr[0], item[2] = arr;

http://es6-features.org/#ObjectMatchingDeepMatching

let { key1, key2{subkey} } = someObject; // => let key1 = someObject->key1, key2 = someObject->key2->subkey;
let { key1, key2[subIndex] } = someObject; // => let key1 = someObject->key1, key2 = someObject->key2["subIndex"];

That's if you want to reinvent the wheel, then please stay as close as some standardized language.
Otherwise stick as close as PHP as possible (using parenthesis) :
let [a, , c] = arr;
Edit: bracket [] is the new standard of PHP7

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