-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Incorrect handling of begin/end while #575
Comments
You know, now that I think about it that behavior from MRI is kind of strange: puts "hi" while false # Prints nothing
begin
puts "konichiwa"
end while false
# Prints "konichiwa"
puts "hi" if false # Prints nothing
begin
puts "konichiwa"
end if false
# Prints nothing 😜 |
The first one is a do-while (special form). The second one is a postfix if |
@Nami-Doc Yes, I realize it's there to allow do-while. I just think it's funny that postfixing |
@Ajedi32 My opinion is nothing strange here.
So that behavior is very logical. |
@sergey-kucher Except that Ruby's behavior is inconsistent with that interpretation in this case: puts "hi" while false # Prints nothing 😝 Obviously I'm not saying Opal should implement this differently, I'm just saying the existing behavior feels kind of strange (even though I understand why it was done that way). |
I think in the we'll just look at rubyspec. I know for sure that some stuff has been "marked" as bug by Matz himself. Anyway I don't think I'll ever use this "feature" :P I also consider this rather low-priority :) |
Yeah, for more on the usage of this feature: http://stackoverflow.com/questions/136793/is-there-a-do-while-loop-in-ruby Also, apparently Matz agrees with me: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/6745 |
@Ajedi32 |
Will keep this open and will find out who will come first, if the MRI that will remove this feature eventually or us implementing it 😄 Here's the response from matz, just for reference
|
On the plus side, this may improve performance, unfortunately it is not in a performance critical code path.
Opal seems to evaluate the condition in a begin/end while loop before executing the scope while MRI runs it once before checking the condition.
The following code will print "konichiwa" in MRI but not in Opal.:
Regular while loops work fine and have their condition checked both in MRI and Opal:
The text was updated successfully, but these errors were encountered: