F
Fred Talpiot
In Ruby:
1) 'if' can be followed by 'elsif'.
2) 'unless' can NOT be followed by 'elsif'. It gets a syntax error.
3) 'unless' can be followed by 'elsunless', but it does not run okay.
3a) 'if' can also be followed by 'elsunless', with the same dismal
results.
4) So what's the standard?
5) The following code:
-------------------
puts 'ruby version: ' + RUBY_VERSION + ', ' + RUBY_RELEASE_DATE + ' for
' + RUBY_PLATFORM
unless true
puts "wrong wrong"
elsunless false
puts 'weird, but logical'
elsunless true
puts 'truly strange'
else
puts 'weirder yet' # This is what pops out!
end
# and 'elsif' is a syntax error following 'unless'
-------------------
Produces the following on WinXP:
weirder yet
And, on Linux:
$ ruby unless.rb
ruby version: 1.8.6, 2007-09-24 for x86_64-linux
weirder yet
We can be sure this behavior is not as intended. We cannot be sure
exactly what was intended.
The following rule is from the wiki reference page:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#unless
|The unless expression is treated exactly like a negated if
expression:
|
| if !expression # is equal to using
| unless expression
Obviously, that rule is not being followed. If it were, the 'elsif'
would
be permitted.
The interpreter has a bug. The documentation may also be wrong, hard to
know for sure...
name already taken
1) 'if' can be followed by 'elsif'.
2) 'unless' can NOT be followed by 'elsif'. It gets a syntax error.
3) 'unless' can be followed by 'elsunless', but it does not run okay.
3a) 'if' can also be followed by 'elsunless', with the same dismal
results.
4) So what's the standard?
5) The following code:
-------------------
puts 'ruby version: ' + RUBY_VERSION + ', ' + RUBY_RELEASE_DATE + ' for
' + RUBY_PLATFORM
unless true
puts "wrong wrong"
elsunless false
puts 'weird, but logical'
elsunless true
puts 'truly strange'
else
puts 'weirder yet' # This is what pops out!
end
# and 'elsif' is a syntax error following 'unless'
-------------------
Produces the following on WinXP:
ruby version: 1.8.6, 2007-09-24 for i386-mswin32ruby unless.rb
weirder yet
And, on Linux:
$ ruby unless.rb
ruby version: 1.8.6, 2007-09-24 for x86_64-linux
weirder yet
We can be sure this behavior is not as intended. We cannot be sure
exactly what was intended.
The following rule is from the wiki reference page:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#unless
|The unless expression is treated exactly like a negated if
expression:
|
| if !expression # is equal to using
| unless expression
Obviously, that rule is not being followed. If it were, the 'elsif'
would
be permitted.
The interpreter has a bug. The documentation may also be wrong, hard to
know for sure...
name already taken