ozra / onyx-lang

The Onyx Programming Language
Other
96 stars 5 forks source link

Add splat and discard to multiple assign #40

Open ozra opened 8 years ago

ozra commented 8 years ago

See #17.

[x, y, _, ...z, u, v] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
-- => x = 1, y = 2, z = [4, 5, 6, 7], u = 8, v = 9

Proposition is that the splat, if used, takes the type of the right hand side.

stugol commented 8 years ago

Sounds good.

Why ... instead of *, incidentally? Are we planning some awesome feature for a unary *?

stugol commented 8 years ago

Suggest alternative syntax for dropping values: simply put nothing (or whitespace) between the commas:

[x, y, , ...z, u, v] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ozra commented 8 years ago

I just find ...ends-up-here to be more telling, might just be me though. In Onyx * has the notion of "catch anything", like the "good ole glob", for instance in match constructs, where I find it is both terse and obvious. But, as you know - It's not cut in stone though! :)

Well founded propositions for even grander changes are acceptable. It's got to get good as it gets, that's the target. There just has to be studies, empirical data or really good arguments (because there are so many things where no studies are available or really point to anything significant) to change / add things.

Alternative noted, I prefer the explicit _ for the reason that it instill certainty in the code reader that it's intended and not a slip. There's gotta be real good reason to ditch one single char for that uncertainty, don't you think?

stugol commented 8 years ago

I prefer the explicit _ for the reason that it instill certainty in the code reader that it's intended and not a slip.

I guess you have a point.