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

Implement multiple comma-separated variable declarations in 'my' statement #199

Closed
masak opened this issue Sep 21, 2016 · 2 comments
Closed

Comments

@masak
Copy link
Owner

masak commented Sep 21, 2016

Like this:

my temperature = 37,
   pressure = 19,
   balloonCount = 65;

Note that this is incompatible with both Perl 5/6 and Python 2/3. Both of these families of languages prefer what we might call "parallel assignment" when declaring:

my ($temperature, $pressure, $balloonCount) = 37, 19, 65;    # Perl
temperature, pressure, balloonCount = 37, 19, 65      # Python

We find a friend in JavaScript, though, and model this feature on it:

var temperature = 37,
    pressure = 19,
    balloonCount = 65;

The biggest difference in practice is that in serial assignment, earlier variables in the same declaration can already be used when assigning to later ones:

my temperature = 37,
   pressure = 19,
   ratio = temperature / pressure;    # didn't even try to get the units right

Oh, and it's also fine to omit the assignment, as usual, and get None.

We're allowed — encouraged, even — to create any kind of API for declaring variables to make this work. It's considered a part of the challenge that we use the my keyword even for this new serial-assignment declaration. Of course declaring only one variable should still work rather than, say, cause a parsing rule conflict.

@masak
Copy link
Owner Author

masak commented Oct 5, 2017

The biggest difference in practice is that in serial assignment, earlier variables in the same declaration can already be used when assigning to later ones

Cf parameter defaults in #112.

@masak
Copy link
Owner Author

masak commented Feb 9, 2019

#279 (correctly) states that if we went ahead and made my into a term, then this issue would become kinda moot. More exactly, this is now definitely a compile-time error:

my a = 1, b = 2;

(That b there is undeclared.)

Closing.

@masak masak closed this as completed Feb 9, 2019
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

1 participant