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

Switch statements cause compile errors #36

Open
benekastah opened this issue Jun 21, 2011 · 7 comments
Open

Switch statements cause compile errors #36

benekastah opened this issue Jun 21, 2011 · 7 comments

Comments

@benekastah
Copy link
Contributor

And when this is fixed, it would also be nice if break statements aren't required. They're silly. I would like something like:

switch foo {
  case :bar:
    aha()
  case :batz:
    doSomething()
    fallthrough
  default
    bar()
}

Just an idea.

@weepy
Copy link
Owner

weepy commented Jun 21, 2011

ideally I'd like to keep compatibility with Javascript. Perhaps there's
another way ?

On Tue, Jun 21, 2011 at 5:36 AM, benekastah <
reply@reply.github.com>wrote:

And when this is fixed, it would also be nice if break statements
aren't required. They're silly. I would like something like:

switch foo {
 case :bar:
   aha()
 case :batz:
   doSomething()
   fallthrough
 default
   bar()
}

Just an idea.

Reply to this email directly or view it on GitHub:
#36

@benekastah
Copy link
Contributor Author

There's always the ruby way. That's the best variation of the switch I've used.

// this is only ruby-ish
case thing {
  when 'rock', 'roll'
    rockNRoll()
  else
    goHome()
    beSad()
}

Then if you really need to use the fallthrough capability, you can just write your switch in pure js.

@weepy
Copy link
Owner

weepy commented Jun 21, 2011

how about

switch thing
 when 'rock', 'roll':
   rockNRoll()
 else:
   beSad()

? do we want/need the colons ?

On Tue, Jun 21, 2011 at 8:31 AM, benekastah <
reply@reply.github.com>wrote:

There's always the ruby way. That's the best variation of the switch I've
used.

case thing
 when 'rock', 'roll'
   rockNRoll()
 else
   beSad()

Reply to this email directly or view it on GitHub:
#36 (comment)

@benekastah
Copy link
Contributor Author

Yeah, I actually kind of like the colons. It's a little more javascripty, and they help me a bit visually.

@weepy
Copy link
Owner

weepy commented Jun 21, 2011

yeah agreed.

maybe we don't need the else as it doesn't add anything beyond 'default' ?

On Tue, Jun 21, 2011 at 8:41 AM, benekastah <
reply@reply.github.com>wrote:

Yeah, I actually kind of like the colons. It's a little more javascripty,
and they help me a bit visually.

Reply to this email directly or view it on GitHub:
#36 (comment)

@benekastah
Copy link
Contributor Author

True. default would be better in this context.

@weepy
Copy link
Owner

weepy commented Jun 21, 2011

ok so :

switch thing {
 when 'rock', 'roll':
   rockNRoll()
 when 'jazz':
    jazz()
 default:
   beSad()
}

which is converted to :

switch(thing) {
 case 'rock':
   rockNRoll(); break; case 'roll': rockNRoll(); break;
 case 'jazz':
   jazz(); break;
 default:
   beSad()
}

On Tue, Jun 21, 2011 at 8:46 AM, benekastah <
reply@reply.github.com>wrote:

True. default would be better in this context.

Reply to this email directly or view it on GitHub:
#36 (comment)

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

No branches or pull requests

2 participants